Forum Moderators: coopster

Message Too Old, No Replies

Dynamically changing option for a select dropdown menu

dropdown value dynamically

         

Gruessle

6:21 am on Feb 28, 2005 (gmt 0)

10+ Year Member



I don't know how to search for a solution on this. Actually I saw some jawascript stuff but I like to keep my site clean php if possible.

I have 3 select boxes and when the user makes his selection on the first one I like the options on the other two to change.
If there is no solution since php is server side the first select box could also be links. I have only 4 items in there.

The js stuff had codes to recognice what type of browser the client is using and that just turns me off.
Here is the link to the js I found:
[p2p.wrox.com...]

jamie

3:48 pm on Feb 28, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hi gruessle,

that is js stuff i'm afraid. php can't change on page elements, as you correctly said.

i'm no js expert, but you should be able to find js code which works pretty much across the board, without having to sniff browsers. have a look in the js forum here.

good luck

hughie

4:15 pm on Feb 28, 2005 (gmt 0)

10+ Year Member



Hi There

if you're willing to refresh the page based on the input in the first select then PHP can do it, otherwise it's client side JS

i posted this on a similar thread a while back but the principal is the same. using JS onchange; to refresh the form

<?php
// DBASE CONECT HERE

//
if (isset($_POST['finalsubmit']))
{
// PROCEED TO NEXT FORM
}
else
{
if (isset($_POST['select1']) && $_POST['select1']!=0)
{
$result=mysql_query("SELECT * FROM states WHERE country_id=$_POST[select1] ");
$thestates='STATES <select name="states">';
while($row=mysql_fetch_array($result))
{
// RETURN DETAILS OF THE COUNTRY CHOSEN
$thestates.='<option value="'.$row[State_ID].'">'.$row[State].'</option>';
}
$thestates.='</select>';
}
}

?>
<html>
<head>
<SCRIPT language="JavaScript">
function submitform()
{
document.form1.submit();
}
</SCRIPT>
</head>
<body>
<form name="form1" method="post" action="<?php echo $_SERVER[PHP_SELF];?>">

<select name="select1" onChange="javascript:submitform();">
<option value="0" selected>Please Choose a Country</option>
<option value="1">UK</option>
<option value="2">USA</option>
</select>
<?php echo $thestates;?>
<Br><br>
<input type="submit" name="finalsubmit" value="FINAL SUBMIT">
</form>
</body></html>

hope that helps

hughie