JS Function in PHP && GET THE RETURNED VALUE in PHP
Posted: Wed Jan 31, 2007 11:26 am
Hi,
I have been struggling from a long time to accomplish dependable select boxes in my php page. I have a select box say s1, which, on change should effect a few other select boxes say s2, s3, s4 to change options (ofcourse based on the value of s1).
What i did is - i wrote a JS function to get the value selected from s1 and i'm calling this JS function from onchage event in s1 like:
The populatelist Is a PHP function that populates the list from dB. THE JAVASCRIPT FUNCTION IS:
Now my problem is: To set the options for s2, s3, s4 based on s1.value, I NEED THAT VALUE ($chosen) in php to select the options for s2 s3 and s4 fromdB. Once it is out of the function the $chosen is not retaining it's value. I have quite a few pages where i have to implement this but i'm not able to proceed. Any help/suggestions/questions are welcome. Thanks for your help.
- Vamz
I have been struggling from a long time to accomplish dependable select boxes in my php page. I have a select box say s1, which, on change should effect a few other select boxes say s2, s3, s4 to change options (ofcourse based on the value of s1).
What i did is - i wrote a JS function to get the value selected from s1 and i'm calling this JS function from onchage event in s1 like:
Code: Select all
<td><b>Partner:</b>
<select name="partnername" onChange = 'Get_Selected_Item(document.serverform.partnername);'>
<?php
populatelist('vendor_id','servermodeltable', 'DELL');
?>
</select>
</td>Code: Select all
<script = "javascript">
function Get_Selected_Item(obj)
{
alert('In the JS Function');
len = obj.options.length;
i = 0;
$chosen = "none";
for (i = 0; i < len; i++)
{
if (obj.options[i].selected)
{
$chosen = obj.options[i].value;
}
}
window.location.reload();
return $chosen;
}
</script>- Vamz