Jump to content

reload form?


techker

Recommended Posts

hey guys is tehre a way to put a select box on a page that when you select the lets say categorie it refreshe's the form to get the info(mysql) in that category?

 

i have tryed lots of was some worked but when i trye to put more then one on a page it refreshe's the first and second box..

 

i have tryed googling javascript event handler

 

onchange.

 

but i cant find a page that shows a for with a select box refresh...

Link to comment
Share on other sites

so i fanaly found one that maybe has potential!lol

 

xml and ajax.

 

it works good but if i add another on the page and changed the get page to fincity2 and the divtag to city2

 

the both work but when i select the second one it changes the first one.

 

i will barke down the code:

 

the xml

 

<script>
function getXMLHTTP() { //fuction to return the xml http object
	var xmlhttp=false;	
	try{
		xmlhttp=new XMLHttpRequest();
	}
	catch(e)	{		
		try{			
			xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e){
			try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e1){
				xmlhttp=false;
			}
		}
	}

	return xmlhttp;
}



function getCity(strURL) {		

	var req = getXMLHTTP();

	if (req) {

		req.onreadystatechange = function() {
			if (req.readyState == 4) {
				// only if "OK"
				if (req.status == 200) {						
					document.getElementById('citydiv').innerHTML=req.responseText;	
					(						
				} else {
					alert("There was a problem while using XMLHTTP:\n" + req.statusText);
				}
			}				
		}			
		req.open("GET", strURL, true);
		req.send(null);
	}

}
</script>


[code]

and the form

[code=php:0]
<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="150">Country</td>
    <td  width="150"><select name="country" onChange="getCity('findcity.php?country='+this.value)">
<option value="">Select Country</option>
<option value="ABS">ABS</option>
    <option value="ARMS">ARMS</option>
     <option value="LEGS">LEGS</option>
      <option value="SHOULDERS">SHOULDERS</option>
       <option value="CHEST">CHEST</option>
        </select></td>
  </tr>
  <tr style="">
    <td>City</td>
    <td ><div id="citydiv"><select name="city">
<option>Select City</option>
        </select></div></td>

 

and the reference page for the query is

 

<? $country=$_REQUEST['country'];
$link = mysql_connect('localhost', 'openshar_techker', 'techker'); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('openshar_trainerstool');
$query="select * from $country ";
$result=mysql_query($query);

?>
<select name="city">
<option>Select City</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value><?=$row['pic']?></option>
<? } ?>
</select>
[/php

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.