javascript - How do I disable specific form elements in a large form -
i must sincerely thank darren davies following code have made test html file.
<html> <head> <title>field_enable</title> <script type="text/javascript" src="script/jquery.js"></script> <script> $().ready(function() { $('#clicker').click(function() { $('input').each(function() { if ($(this).attr('disabled')) { $(this).removeattr('disabled'); } else { $(this).attr({ 'disabled': 'disabled' }); } }); }); }); </script> </head> <body> <div id='clicker' style='background-color:#ff0000; height:20px; width:50px;'></div> <br> <input type='text' disabled></input> <input type='text' disabled></input> <input type='text' disabled></input> </body> </html>
this works form has large number if fields within need disable 1 various clients. when apply code activates fields have disabled disables rest of fields in form though have no attribute set. problem work out how activate fields have disabled , leave rest enabled.
if want affect fields assign fields particular class (changeable in example)
<input type='text' disabled class="changeable" />
and change line
$('input').each(function() {
to
$('input.changeable').each(function() {
so works on inputs given class
Comments
Post a Comment