|
Subject:
|
OnChange issue
|
|
Posted By:
|
kdyer
|
Post Date:
|
7/20/2006 10:18:32 AM
|
Hi there. I am pretty new to PHP and finding it pretty cool..
Having problem with the following code..
Have the Select working fine on opening the page, but the ONSUBMIT is not printing the desired results.
Copied the code from: http://p2p.wrox.com/topic.asp?TOPIC_ID=17383
<html>
<head>
<title>Test</title>
</head>
<body>
<?php
//http://p2p.wrox.com/topic.asp?TOPIC_ID=17383
$city = null; //declare vars
$conn = mysql_connect ("localhost","login","password");
$db = mysql_select_db('database',$conn);
if(isset($_GET["city"]) && is_numeric($_GET["city"]))
{
$city = $_GET["city"];
}
?>
<script language="JavaScript">
function autoSubmit()
{
var formObject = document.forms['theForm'];
formObject.submit();
}
</script>
<form name="theForm" method="get">
<select name="city" onChange="autoSubmit();">
<option value="null"></option>
<?php
//POPULATE DROP DOWN MENU WITH STATES FROM A GIVEN REGION, COUNTRY
$sql = "SELECT DISTINCT city FROM lodges";
$cityname = mysql_query($sql,$conn);
while($row = mysql_fetch_array($cityname))
{
echo ("<option value=\"$row[city]\" ".($city == $row["city"] ? " selected" : "").">$row[city]</option>");
}
?>
</select>
<?php
if($city != null)
{
//POPULATE DROP DOWN MENU WITH CITIES FROM A GIVEN REGION, COUNTRY, STATE
$sql = "SELECT id, secretary FROM lodges WHERE city = $city ";
$secretaries = mysql_query($sql,$conn);
while($row = mysql_fetch_array($secretaries))
{
echo $row[secretary];
}
?>
</form>
</body>
</html>
The dropdown works great, but I see no restults onchange..
Thanks,
Kent
|
|
Reply By:
|
kdyer
|
Reply Date:
|
7/21/2006 4:32:01 PM
|
Never mind.. Got it to work.. had to make some change with $_POST and $_GET.. It works great now.
Thanks,
Kent
|
|
Reply By:
|
kumarj
|
Reply Date:
|
10/4/2006 6:45:33 AM
|
hi ,pls check this you r not menson the ACTION attribute in the form tag. To list selected item values ,select query with selected item.
|
|