Skip to content Skip to sidebar Skip to footer

Why Is This Code To Disable An Html Select Box Not Working?

function abc() { document.form1.1.disabled=true; } I have a select box whose id is 1 in my HTML page. I am using the JavaScript above but it is not disabling the select box.

Solution 1:

ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").

http://www.w3.org/TR/html4/types.html#type-name

Fix the underlying problem. Don't have ids that start with a number.

Solution 2:

var elem = document.getElementById("1");
elem.setAttribute("disabled","disabled");

Solution 3:

document.form1 contains a list of input elements, selectboxes and textareas. document.form1.1 is the same as saying document.form1[1] and gets the second element in that list. Try

document.getElementById("1").disable = true;

Post a Comment for "Why Is This Code To Disable An Html Select Box Not Working?"