Jump to content

Disable Certain Input Boxes With Javascript


Macchiato

Recommended Posts

I'd like to disable certain input boxes, but without changing the HTML code manually. For example:I'd like to disable the input boxes with the following id's:id="first_field"id="fourth_field"id="sixth_field"

  <div>	<form action="">	  <fieldset>		<input type="text" id="first_field"/>		<input type="text" id="second_field"/>		<input type="text" id="third_field"/>		<input type="text" id="fourth_field"/>		<input type="text" id="fifth_field"/>		<input type="text" id="sixth_field"/>	  </fieldset>	</form>  </div>

Anyone know a Javascript that can do this?

Link to comment
Share on other sites

is there any reason you can't take anything you've been taught herehttp://w3schools.invisionzone.com/index.php?showtopic=44954 to at least make an attempt on your own first?

Link to comment
Share on other sites

Woah! Take it easy man... eat a pie ;) I always try before I post. Already found a solution:

  <script type="text/javascript">    var els = ["first_field", "fourth_field", "sixth_field"]    for (var i = 0; i < els.length; i++)    document.getElementById(els[i]).disabled = true;  </script>

Link to comment
Share on other sites

thescientist does have a point. It's important that original posters demonstrate more diligence than they frequently do and not be surprised when a responder indicates that the OP should/might know better, might be dallying, or both.

Edited by niche
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...