I'm not very experienced with PHP and I've been told this is a good
place to ask for help.
I have dyanamic dropdowns in a form taken from a DB. Meaning the first
dropdowns is populated by items in the DB and once selected it reloads
the page with javascript and populates the second dropdown based on
the first one.
Ive gotten this to work, however my problem is that once it reloads it
populates the second dropdown but the first dropdown goes back to the
defaulted select option. I want it to stay on the selected one that
populate the second dropdown.
Here is the javascript ive used:
<SCRIPT language=JavaScript>
function reload(form){
var val=form.type.options[form.type.options.selectedIndex].value;
self.location='dropdown.php?type=' + val ;
}
</script>
and heres my PHP code:
<?
include("dbinfo.inc.php");
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$xtype=mysql_query("SELECT DISTINCT type FROM prod");
echo "<form method=post name=f1 action='dropresult.php'>";
////////// Starting of first drop downlist /////////
echo "<select name='type' onchange=\"reload(this.form)\">";
while($type = mysql_fetch_array($xtype)) {
echo "<option value='$type[type]'>$type[type]</option>"."<BR>";
}
echo "</select>";
$sType = $_GET['type'];
echo $sType;
////////// Starting of the second drop downlist /////////
$xquality = mysql_query("SELECT DISTINCT quality FROM prod WHERE
type='".$sType."'");
echo "<select name='quality'><option value=''>Select one</option>";
while($qual = mysql_fetch_array($xquality)) {
echo "<option value='$qual[quality]'>$qual[quality]</option>";
}
echo "</select>";
echo "<input type=submit value=Submit>";
echo "</form>";
?>
I have a feeling the solution might be very simple however it seems to
escape me immensly.
Any help is very much appreciated.
Thanks in advance
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment