Disable Certain Input Boxes With Javascript

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”


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Disable Certain Input Boxes With Javascript</title>
</head>

<body>

  <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>

</body>
</html>

Anyone know a Javascript that can do this?

Hi,

add this to the bottom of your HTML document, just before the closing <body> tag.

<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>

This should do what you want.

Thanks, much appreciated!