Disabling Text field with Javascript when value in drop down box is from mysql
Posted
by SteveJ313
on Stack Overflow
See other posts from Stack Overflow
or by SteveJ313
Published on 2010-05-14T04:12:50Z
Indexed on
2010/05/14
4:24 UTC
Read the original article
Hit count: 183
Hi
I have a simple script in HTML, using a dropdown menu. When the value 1 is selected, the user can write in the text field, if value 2 is selected, it disables the text field.
However, i changed the values of the dropdown menu, so that one value was from a mysql table(using PHP) and the other remained 'option value='1''. Yet now neither text field is disabled. Below is the code.
`<script type="text/javascript">
function findselected() {
if (document.form.selmenu.value == <?php echo $id; ?>) {
document.form.txtField.disabled=true;
// return false; // not sure this line is needed
} else {
document.form.txtField.disabled=false;
// return false; // not sure this line is needed
}
} `
And the PHP section
if(mysql_num_rows($SQL) == 1)
{
echo "<select name='selmenu' onChange='findselected()'>";
echo "<label>TCA_Subject</label>";
while ($row=mysql_fetch_array($SQL)) {
echo "<option value='$id'>$thing</option>";
echo "<option value='2'>Choice 2</option>";
}
}
echo "<option value=$userid>'Choice 1'</option>";
?> <option value='2'>Choice 2</option>";
</select>
I have tried taking the second option value out of the loop, putting it into html, editing the variable in the javascript function. There is not a fault with the PHP as it is retrieving the right results and displaying it, yet the text field doesnt become disabled.
Does anyone know of a possible solution?
Thanks
© Stack Overflow or respective owner