Jump to content

onclick to update option menu feild help


finestice

Recommended Posts

Hi, i got this code online and amended to my needs but im having a problem getting the third field to dynamicly change when i click the second field(im gathering info from a database)

goto http://tyrehq.com/dd1.php to see the code in action... iv managed to dynamicaly change the first and second field but need some help how to do the third as javascript 'onclick' is totally new to me

 

table is

id | make | model | Year etc...

1    audi      a1        2001

2    bmw    z4        2002

3    audi      a4        2001

etc

i want the year to change accord to the model choosen

so if  choose audi + a1 the third feild will only show 2001 and not list all whats in that column - HOPE THIS MAKE SENSE

 

<?php
include 'connect.php';
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Multiple drop down list box from plus2net</title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='dd1.php?cat=' + val ;
}

</script>
</head>

<body>
<?

/*
If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care.
To read more on register_global visit.
  http://www.plus2net.com/php_tutorial/register-globals.php
*/
@$cat=$_GET['cat']; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and is_numeric($cat)){ // to check if $cat is numeric data or not. 
echo "Data Error";
exit;
}

//@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off

///////// Getting the data from Mysql table for first list box//////////
$quer2=mysql_query("SELECT DISTINCT make FROM pressures"); 
///////////// End of query for first list box////////////

/////// for second drop down list we will check if category is selected else we will display all the subcategory///// 
if(isset($cat) and strlen($cat) > 0){
$quer=mysql_query("SELECT DISTINCT make, model FROM pressures WHERE make='$cat' ORDER BY model ASC"); 
}
////////// end of query for second subcategory drop down list box ///////////////////////////

echo "<form action='dd-check.php' method='post'>";
/// Add your form processing page address to action in above line. Example  action=dd-check.php////
//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['make']==@$cat){echo "<option selected value='$noticia2[make]'>$noticia2[make]</option>"."<BR>";}
else{echo  "<option value='$noticia2[make]'>$noticia2[make]</option>";}
}
echo "</select>";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='title'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) { 
echo  "<option value='$noticia[model]'>$noticia[model]</option>";
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////
$query = "SELECT DISTINCT year FROM pressures ORDER BY year DESC";
$result = mysql_query($query);
?>
<select name="year">
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['year'];?>"> <?php echo $line['year'];?> </option>

<?php
}
?>
</select>
<?
//// Add your other form fields as needed here/////
echo "<input type=submit value=Submit>";
echo "</form>";
?>
</body>

</html>

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.