Question on handeling HTML form events
Posted: Mon Oct 27, 2008 1:21 pm
Howdy everyone!
I'm sure this is a pretty simple question, but I wanted to see if I'm barking up the wrong tree or not in my development.
I've been reading "PHP & MySQL for Dummies, 3rd Edition" by Janey Valade. Overall, I'm fairly new to all web programming, but I knew enough HTML from a class I took in '96 to figure out the HTML parts of the book. Well, I've designed a functional registration and payment (paypal) page for the website I am working on (just a basic college alumni chapter site), but now I've hit into a bit of a snag.
I've used php to populate the various drop downs on the form and to redisplay the form with the user data and an error message if something is wrong. However, there is one thing I am stuck on.
I would like the options in the drop downs to display different information based on a choice made earlier in the form.
For instance, there are two drop down lists, one for College and one for Major. If the user selects "Business" in the College drop down, I only want it to show majors from the Business school, so that a user can't select "Business" for College and "Botany" for the major since obviously it's not a major offered in the Business school!
I figure I can do the same thing that I do for when I check the fields for errors and redisplay the whole form, limiting the Majors list at that point to only majors in the college selected. However, that seems like it might not be an efficient solution. Plus, if the server lags a bit, I'd prefer not to have the whole page go blank before it reloads. In other words, I want it to be seamless to the user. I know how to do this in VB and C#, but the book I have doesn't mention this type of thing specifically, and I couldn't seem to frame my question right to find it in a google search!
So, can php do what I want without reloading the whole page? If not, should I be looking at some type of javascript or something? I saw that HTML now has an 'onchange' event you can use with a form, so I figure that would be the spot to key off whatever I am going to do.
Thanks for your help!
I'm sure this is a pretty simple question, but I wanted to see if I'm barking up the wrong tree or not in my development.
I've been reading "PHP & MySQL for Dummies, 3rd Edition" by Janey Valade. Overall, I'm fairly new to all web programming, but I knew enough HTML from a class I took in '96 to figure out the HTML parts of the book. Well, I've designed a functional registration and payment (paypal) page for the website I am working on (just a basic college alumni chapter site), but now I've hit into a bit of a snag.
I've used php to populate the various drop downs on the form and to redisplay the form with the user data and an error message if something is wrong. However, there is one thing I am stuck on.
I would like the options in the drop downs to display different information based on a choice made earlier in the form.
For instance, there are two drop down lists, one for College and one for Major. If the user selects "Business" in the College drop down, I only want it to show majors from the Business school, so that a user can't select "Business" for College and "Botany" for the major since obviously it's not a major offered in the Business school!
I figure I can do the same thing that I do for when I check the fields for errors and redisplay the whole form, limiting the Majors list at that point to only majors in the college selected. However, that seems like it might not be an efficient solution. Plus, if the server lags a bit, I'd prefer not to have the whole page go blank before it reloads. In other words, I want it to be seamless to the user. I know how to do this in VB and C#, but the book I have doesn't mention this type of thing specifically, and I couldn't seem to frame my question right to find it in a google search!
So, can php do what I want without reloading the whole page? If not, should I be looking at some type of javascript or something? I saw that HTML now has an 'onchange' event you can use with a form, so I figure that would be the spot to key off whatever I am going to do.
Thanks for your help!