angel777 Posted April 1, 2008 Share Posted April 1, 2008 hi the below code is to enable textbox with one checkbox.. what if i want to do it with group radio button ? which sharing the same name for 2 group radio .. thanks ="JavaScript"><!-- function codename() { if(document.formname.checkboxname.checked) { document.formname.textname.disabled=false; } else { document.formname.textname.disabled=true; } } //--> </SCRIPT> <form action="" method="" name="formname"> <input type="text" disabled size="10" name="textname"> <input type="checkbox" onclick="codename()" name="checkboxname" value="ON"> <input type="submit" value="Add"> <input type="reset" value="Clear"> </form> Link to comment https://forums.phpfreaks.com/topic/98968-check-radio-enable-textbox/ Share on other sites More sharing options...
zenag Posted April 1, 2008 Share Posted April 1, 2008 can do it with radio buttons ..... like this ... <script type="text/javascript">function codename(str) { if(str=="on") { document.formname.textname.disabled=false; } else if(str=="off") { document.formname.textname.disabled=true; } } </SCRIPT> <form action="" method="" name="formname"> <input type="text" disabled size="10" name="textname"> <input type="radio" onclick="codename(this.value)" name="checkboxname" value="on"> <input type="radio" onclick="codename(this.value)" name="checkboxname" value="off"> <input type="submit" value="Add"> <input type="reset" value="Clear"> </form> Link to comment https://forums.phpfreaks.com/topic/98968-check-radio-enable-textbox/#findComment-506415 Share on other sites More sharing options...
angel777 Posted April 1, 2008 Author Share Posted April 1, 2008 hi thanks ... it works for the above how about i want to change the color i tried that.. but t din change if(str=="on") { document.formname.textname.disabled=false; document.formname.textname.style.color = "white" } else if(str=="off") { document.formname.textname.disabled=true; document.formname.textname.style.color = "gray" } } <input type="text" disabled size="10" name="textname" style="background-color:#CCCCCC"> Link to comment https://forums.phpfreaks.com/topic/98968-check-radio-enable-textbox/#findComment-506434 Share on other sites More sharing options...
zenag Posted April 1, 2008 Share Posted April 1, 2008 do it like this... <script type="text/javascript">function codename(str) { if(str=="on") { document.formname.textname.disabled=false; document.getElementById("textname").style.backgroundColor = "blue"; } else if(str=="off") { document.formname.textname.disabled=true; document.getElementById("textname").style.backgroundColor = "red"; } } </SCRIPT> <input type="text" disabled size="10" id="textname" name="textname"> Link to comment https://forums.phpfreaks.com/topic/98968-check-radio-enable-textbox/#findComment-506447 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.