Jump to content

check radio enable textbox


angel777

Recommended Posts

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

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>

 

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">

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">

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.