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> Quote Link to comment 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> Quote Link to comment 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"> Quote Link to comment 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"> Quote Link to comment 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.