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
https://forums.phpfreaks.com/topic/156829-clickable-text-from-radio-button/
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

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.