sandbudd Posted May 4, 2009 Share Posted May 4, 2009 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> Quote Link to comment Share on other sites More sharing options...
the182guy Posted May 4, 2009 Share Posted May 4, 2009 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 Quote Link to comment Share on other sites More sharing options...
sandbudd Posted May 4, 2009 Author Share Posted May 4, 2009 perfect thanks Quote Link to comment Share on other sites More sharing options...
sandbudd Posted May 4, 2009 Author Share Posted May 4, 2009 that works great...one more question..what if I wanted to have another set of radio buttons effecting different fields on the same form? Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 add a formElemet['input_name'].disabled = disabled; Quote Link to comment Share on other sites More sharing options...
sandbudd Posted May 4, 2009 Author Share Posted May 4, 2009 sorry could you explain a little further please Quote Link to comment Share on other sites More sharing options...
sandbudd Posted May 4, 2009 Author Share Posted May 4, 2009 the182guy could you help me out with this? Quote Link to comment Share on other sites More sharing options...
the182guy Posted May 4, 2009 Share Posted May 4, 2009 Just duplicate the function and give it a different name and use that in the onclick() So you will have two functions, one for each set of fields to disable/enable Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Just duplicate the function and give it a different name and use that in the onclick() So you will have two functions, one for each set of fields to disable/enable Why duplicate it? 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.