I am using a dropdown box with 6 options. On change I want ajax to return part of an HTML/PHP page that corresponds to one of the 6 questions. I was trying to put and if statement on the return page to determine the part that I wanted but I didnt work. I rather not create 6 HTML/PHP files for each of the options. Here is part of the CODE

CREATE A:		
		<select name="mychoice" onchange="onchange_getform(this.value)">
			<option>----Select----</option>
			<option value="1">Application</option>
			<option value="2">Contact</option>
			<option value="3">Program</option>
			<option value="4">Project</option>
			<option value="5">Category</option>
			<option value="6">Question</option> 
		</select>

this part above selects the type i want to create-

function onchange_getform(str)
		
			{
			alert(str);
			if (str=="")
			{
			document.getElementById("mychoice").innerHTML="";
			return;
			} 
			if (window.XMLHttpRequest)
			{// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp=new XMLHttpRequest();
			}
			else
			{// code for IE6, IE5
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			xmlhttp.onreadystatechange=function()
			{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				document.getElementById("create_form").innerHTML=xmlhttp.responseText;
				}
			}
			xmlhttp.open("GET","create_entity.php?q="+str,true);
			xmlhttp.send();

the create_entity has the form layouts for each of the 6 entities. is it possible to distinguish on the page being request ("create_entity") or do i have to make 6 separate ajax call to 6 separate php pages.
if u guys could point me in the right direction that would be great

-jaycastr

sorry it came out hard to read

What does 'alert(str)' show ?

i solved it like this

on the requested page

switch ($_GET['q'])
{
    case 1;
    echo"form stuff";
    break;
    case 2
echo"form stuff";
break;
default:
echo""

}

thanks to though

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.