Jump to content

clickable text from radio button


sandbudd

Recommended Posts

this little script kinda works but what happens are all fields go disabled when clicked and enabled...I only want certain fields to be affected?  or if someone has another script

 

<html>
<head>
<title>Test</title>
<script type="text/javascript">
function disable_controls( repo) {
var frm = document.forms[0] ;
var len = frm.elements.length ;
var cnt = 0 ;
for ( var i=0; i < len; i++) {
var elem = frm.elements[i] ;
if (elem.type != "hidden") {
if (elem.type != "radio") {
elem.disabled = repo ;
}
} 
}
}
</script>
</head> 
<body>

<form action="yours" method="POST" enctype="application/x-www-form-urlencoded">

<input type="radio" value="Yes" name="repo" onclick="disable_controls( false)">Yes
<input type="radio" value="No" name="repo" onclick="disable_controls( true)">No
<br>
<input name="testing" value="what ever" type="text">
<br>
<select name="test" disabled >
  <option value="test">test</option>
  <option value="test2">test2</option>
  <option value="test3">test3</option>
  
</select> </form>
</body> 
</html>

Link to comment
Share on other sites


function disable_controls(value)
{

   var disabled = value ? true : false;

   var formElements = document.forms[0].elements;

   formElements["input1"].disabled = disabled;
   formElements["input2"].disabled = disabled;
   formElements["input3"].disabled = disabled;

}

 

input1, input2 and input3 are form element names which will be disabled/enabled

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.