homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Help with dynamic form
How to use php include with onChange?

 3:34 pm on Nov 28, 2009 (gmt 0)

Not having much of a clue about Javascript and PHP I'm trying to build a somewhat dynamic contact form. First I have the "normal" entries like name, email address, country. Then comes a dropdown with three options, let's call them A, B and C. Depending on what is chosen in this dropdown the rest of the form has different form fields. Can this be done with a php include? So let's say if option A is chosen a different file with the "rest" of the form is included than for option B? And acordingly for C?
Would be greatful for some hints...



 5:37 pm on Nov 28, 2009 (gmt 0)

I am almost certain you can accomplish this with AJAX.


 6:17 pm on Nov 28, 2009 (gmt 0)

Yes, that's what I also came accross. Any idea where I can find examples?


 9:34 pm on Nov 28, 2009 (gmt 0)

I'm quite a fan of jQuery for javascript bits like this. Especially if you're not very comfortable with native javascript. There are a few examples of what you want to accompolish. Just a quick idea of the code (if you do go the jQuery way)

say you have a div that holds where the includes should go called #includes you could include the following in a script block

$('select #dropdown').change(function(){
var val = $(this).val();
if(val == 1){
if(val == 2){

This is a very simple example and you will have to do some more work to get it working how you want it. One thing you should consider is what if a user doesn't have js enabled. Unless you know for certain that they will always have js on, you could look at doing something with the querystring. You could also use this to drive the ajax style functionality you are after.


 8:11 pm on Nov 29, 2009 (gmt 0)

Thanks, Tommy, I will definitely have a look at jQuery even though I'm not really goood with that stuff...


 6:34 pm on Dec 2, 2009 (gmt 0)


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved