I have that working fine for php and that is exactly how I did it. My problem with this method is you must provide an array of values to populate the select list. In my case there are some pretty large lists for states, dollar values etc. So I had to go through by hand and type out these arrays to pass to my generateSelect function. I figured using javascript would be easier sonce I could just have it iterate through each option and check the value then set the selcted value to true when found.
Here is the javascript code that my php variable gets passed to:
Code:
function setState(val){
for (var i = 0; i < document.form.state.length; i++) {
if (document.form.state.options[i].value == val)
document.form.state.options[i].selected = true;
}
}
And here is how I call the function from html:
Code:
<script language="JavaScript">
setState(<?php echo $state ?>);
</script>
Is there a problem in the way I am calling the function? Does it need to be triggered somehow? I know this is possible since it is well documented all over the net, I have just never done it before...
Last edited by Jasonpv; 01-19-2010 at 03:46 PM..
|