PDA

View Full Version : PHP Selects and output - dynamic update?



gwmbox
01-12-2009, 03:38 AM
Hi guys

I have two select boxes of which a user will select an item from select box 1 and then select box 2 will refresh with options that only match the first selected select box.

Second is that I need to have a hidden form output to dynamically change also based on the selection of select box 1.

How do I do this within php, or do I need to use javascript?

I was trying to use strpos but while that works it does not dynamically change the select boxes...


<?php
$size = 'asize';
$findme = 'asizestring';
$sel = strpos($size, $findme);

if ($sel === false) {
echo '<option value="option1Choice1" selected>Option1 choice1</option>
<option value="option1choice2">option1choice2</option>';
} else {
echo '<option value="option2choice1" selected>option2 Choice1</option>
<option value="option2choice2">option2 choice 2';
}
?>

help please :)

Cheers

gpigate
01-13-2009, 02:16 AM
i have somewhat the same thing in a page I have. my select lists are for states and counties.

the cid var below is a hidden value in the form. then based on the state id passed in the url i then load the counties list.


<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.state_id.options[form.state_id.options.selectedIndex].value;
var cid=form.clubid.value;
self.location='yoururl&clubid=' + cid + '&state_id=' + val ;
}
</script>

then in the html
echo "<select name='state_id' onchange=\"reload(this.form)\"><option value=''>Select a State</option>";

this is the county select based on the state_id passed
if(isset($state_id) and strlen($state_id) > 0){
$cquery=mysql_query("SELECT * FROM ".$prefix."_counties where state_id=$state_id order by name");
}

careful as your submit button cant be named "submit"