rsammy Posted March 25, 2008 Share Posted March 25, 2008 i have a screen where apart from other fields, i have these two fields: <tr> <td><div align="right"><font class="inputLbl">Wireless Access: </font></div></td> <td><select name="wirelessaccess" > <? if (isset ($wireless)) { print ("<option value='$wireless' selected>$wireless</option>"); if ($wireless == "Yes") { print("<option value='No'>No</option> "); } elseif ($wireless == "No") { print("<option value='Yes'>Yes</option>"); } } else { print("<option value='No' selected>No</option> "); print("<option value='Yes'>Yes</option>"); } ?> </select></td> </tr> <tr> <td><div align="right"><font class="inputLbl">PIN: </font></div></td> <td><input name="phypin" type="text" class="txtboxLarge" id="phypin" value="<?PHP print($rowz["phy_pin"]); ?>"></td> </tr> what i need to do is, be able to enter some info in the field if the wirelessaccess field takes the value 'Yes'. the field can be made readonly if wireless access field takes 'No'. How can i do this? i am stuck at this point. is this possible with php - i guess php is a server side script. any help will be gladly appreciated. thanx in advance Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/ Share on other sites More sharing options...
Northern Flame Posted March 25, 2008 Share Posted March 25, 2008 i dont really understand what you are trying to do, you have a select tag, and depending on the results of what the user selects you want to echo either an input where the user puts more info or a read only input tag with pre-written info? is that what you are trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/#findComment-500587 Share on other sites More sharing options...
rsammy Posted March 25, 2008 Author Share Posted March 25, 2008 no no no. the wirelessaccess field is a drop down with 'Yes' or 'No' as the options. If user selects 'Yes' here, then the next field on screen, PIN is a write only field where user enters a pin ( i am doing PIN validations on this field to make sure the correct one gets thru). If the user chooses 'No' for wirelessaccess field, then the PIN field is made 'readonly' user cannot edit this field. this field may or maynot be blank onload. if wireless acess is 'Yes', the PIN field is mandatory(where user enters info) else the field is readonly(user cannot enter any info). hope im clear now... Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/#findComment-500596 Share on other sites More sharing options...
discomatt Posted March 25, 2008 Share Posted March 25, 2008 This is javascript, not PHP Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/#findComment-500602 Share on other sites More sharing options...
rsammy Posted March 25, 2008 Author Share Posted March 25, 2008 so this is not possible with php? Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/#findComment-500604 Share on other sites More sharing options...
Northern Flame Posted March 25, 2008 Share Posted March 25, 2008 oh, now i understand, you can do this with javascript, try this code before your form <script type="text/javascript"> function checkPin(yesno){ if(yesno == 'yes'){ document.forms[0].phypin.disabled=false; } else{ document.forms[0].phypin.disabled=true; } } </script> (the code above will only work if this is the only form on that page, if not add the name attribute to the form and change the 0 in the brackets where it says forms and add the name of the form) then add this code: <tr> <td><div align="right"><font class="inputLbl">Wireless Access: </font></div></td> <td><select name="wirelessaccess" > <? if (isset ($wireless)) { print ("<option value='$wireless' selected>$wireless</option>"); if ($wireless == "Yes") { print("<option onClick=\"checkPin('no')\" value='No'>No</option> "); } elseif ($wireless == "No") { print("<option onClick=\"checkPin('yes')\" value='Yes'>Yes</option>"); } } else { print("<option onClick=\"checkPin('no')\" value='No' selected>No</option> "); print("<option onClick=\"checkPin('yes')\" value='Yes'>Yes</option>"); } ?> </select></td> </tr> <tr> <td><div align="right"><font class="inputLbl">PIN: </font></div></td> <td><input name="phypin" type="text" class="txtboxLarge" id="phypin" value="<?PHP print($rowz["phy_pin"]); ?>"></td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/#findComment-500614 Share on other sites More sharing options...
rsammy Posted March 25, 2008 Author Share Posted March 25, 2008 thanx northern flame! ill try that out. Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/#findComment-500639 Share on other sites More sharing options...
Northern Flame Posted March 25, 2008 Share Posted March 25, 2008 let me know if it works Quote Link to comment https://forums.phpfreaks.com/topic/97842-help-with-field-enabledisable/#findComment-500649 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.