homepage Welcome to WebmasterWorld Guest from 54.197.19.35
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
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?
bluemi




msg:4033226
 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...

 

smatts9




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

I am almost certain you can accomplish this with AJAX.

bluemi




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

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

Tommybs




msg:4033333
 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


$(function(){
$('select #dropdown').change(function(){
var val = $(this).val();
if(val == 1){
$('#includes').load('include1.php');
}
if(val == 2){
$('#includes').load('include2.php');
}
});
});

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.

bluemi




msg:4033635
 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...

NomikOS




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

[marcgrabanski.com...]

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