Question on handeling HTML form events

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ncarty97
Forum Newbie
Posts: 6
Joined: Mon Oct 27, 2008 1:07 pm

Question on handeling HTML form events

Post by ncarty97 »

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!
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Question on handeling HTML form events

Post by VladSun »

Search for AJAX and chained select boxes.
There are 10 types of people in this world, those who understand binary and those who don't
ncarty97
Forum Newbie
Posts: 6
Joined: Mon Oct 27, 2008 1:07 pm

Re: Question on handeling HTML form events

Post by ncarty97 »

Thanks! I'll check it out.
Post Reply