Arrays and selects

M

Mike

Hi all,

How do I set this to "disabled":

<select name="awards[]" multiple size="6">
<option value="1">Award 1</option>
<option value="2">Award 2</option>
<option value="3">Award 3</option>
<option value="4">Award 4</option>
</select>

I don't know how many options there will be as they are fed from a DB.

Thanks very, very much in advance.

Mike
 
M

Michael Winter

How do I set this to "disabled":

When you say, "this", to what are you referring? The whole SELECT element,
or just some (or all) of the OPTIONS?

[snip]

Mike
 
G

Grant Wagner

Mike said:
Hi all,

How do I set this to "disabled":

<select name="awards[]" multiple size="6">
<option value="1">Award 1</option>
<option value="2">Award 2</option>
<option value="3">Award 3</option>
<option value="4">Award 4</option>
</select>

I don't know how many options there will be as they are fed from a DB.

Thanks very, very much in advance.

Mike

document.forms['yourFormName'].elements['awards[]'].disabled = true;

If you are calling this from someplace on the form, say a button, and you
already have a reference to the form, you could do something like:

<input type="button"
value="Toggle Awards"
onclick="this.form.elements['awards[]'].disabled =
!this.form.elements['awards[]'].disabled;"
A shorter form when toggling might be:

this.form.elements['awards[]'].disabled ^= true;

No guarantees it'll work since it turns the result into a number and
assigning 0 or 1 to disabled may not work - although they should be type
converted to a boolean - 0 being false, 1 being true. You'll have to test
it to see if it works (assuming toggling the disabled property is what you
want to do).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top