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

 

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.