Jump to content

Create a form when a drop down box is changed?


DataSpy

Recommended Posts

I'm very new to ajax and javascript in general so hopefully this isn't a stupid question.  What I want to happen is when a drop down box is changed I want a form to materialize, obviously a different form for a different selection.

 

flow chart kind of thing

drop down box >> make selection (onchange) >> build form without refreshing page

Link to comment
Share on other sites

 

function fillForm(formNameToGet){
//Create an XMLHttpRequest object
if (window.XMLHttpRequest) {
	/*code for IE7+, Firefox, Chrome, Opera, Safari*/
	xmlhttp=new XMLHttpRequest();
}
else{
	/* code for IE6, IE5*/
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
/*Create the function to be executed when the server response is ready*/
xmlhttp.onreadystatechange=function(){
	if (xmlhttp.readyState==4 && xmlhttp.status==200){
		document.getElementById('formBox').innerHTML=xmlhttp.responseText;
	}
}
  	/*Send the request off to a file on the server*/
xmlhttp.open("GET","http://www.mysite.net/ajaxProcessor.php?getForm="+formNameToGet,true);
xmlhttp.send();
}

 

 

1 call the function

2 php script receives the variable 'getForm' in the get

3 php then echo's back the html for the form which is captured in the responseText

4 the js then fills the div with id 'formBox' with the html outputted from the php and captured in the responseText.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.