bauhsoj
03-09-2005, 04:21 AM
Say I have the following PHP code:
<form name="value_list" method="POST" action="value_lister.php">
<?php
foreach ($somevar as $k=>$v) {
?>
<tr>
<td>
<input name="form_var[<?=$k ?>][name]" type="text" size="40" value="<?=$v['name'] ?>" />
</td>
<td>
<input name="form_var[<?=$k ?>][number]" type="text" size="8" value="<?=$v['number'] ?>" />
</td>
<td>
<select name="form_var[<?=$k ?>][type]">
<option value="static" onClick="document.value_list.form_var[<?=$k ?>][number].disabled=false"<?=($v['type']=='static'?' selected':'') ?>>Static</option>
<option value="dynamic" onClick="document.value_list.form_var[<?=$k ?>][number].value='';document.value_list.form_var[<?=$k ?>][number].disabled=true"<?=($v['type']=='dynamic'?' selected':'') ?>>Dynamic</option>
</select>
</td>
</tr>
<?php
}
?>
</form>
How would I get the JavaScript embedded in the options of <select name="form_var[<?=$k ?>][type]"> to function correctly, disabling or enabling the specific form_var[<?=$k ?>][number] field? The above does not seem to work as-is.
I figure this has probably been asked before but I couldn't find a correct solution to what I was looking for...unless I have misread some other posts. I am not so great with JavaScript, unfortunately. :rolleyes:
Thanks in advance for any help!
<form name="value_list" method="POST" action="value_lister.php">
<?php
foreach ($somevar as $k=>$v) {
?>
<tr>
<td>
<input name="form_var[<?=$k ?>][name]" type="text" size="40" value="<?=$v['name'] ?>" />
</td>
<td>
<input name="form_var[<?=$k ?>][number]" type="text" size="8" value="<?=$v['number'] ?>" />
</td>
<td>
<select name="form_var[<?=$k ?>][type]">
<option value="static" onClick="document.value_list.form_var[<?=$k ?>][number].disabled=false"<?=($v['type']=='static'?' selected':'') ?>>Static</option>
<option value="dynamic" onClick="document.value_list.form_var[<?=$k ?>][number].value='';document.value_list.form_var[<?=$k ?>][number].disabled=true"<?=($v['type']=='dynamic'?' selected':'') ?>>Dynamic</option>
</select>
</td>
</tr>
<?php
}
?>
</form>
How would I get the JavaScript embedded in the options of <select name="form_var[<?=$k ?>][type]"> to function correctly, disabling or enabling the specific form_var[<?=$k ?>][number] field? The above does not seem to work as-is.
I figure this has probably been asked before but I couldn't find a correct solution to what I was looking for...unless I have misread some other posts. I am not so great with JavaScript, unfortunately. :rolleyes:
Thanks in advance for any help!