Tarun
Tarun

Reputation: 267

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.

Upvotes: 1

Views: 1305

Answers (3)

TheVillageIdiot
TheVillageIdiot

Reputation: 40497

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

Upvotes: 1

Marius
Marius

Reputation: 58911

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;

Upvotes: 0

Quentin
Quentin

Reputation: 943185

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.

Upvotes: 3

Related Questions