Click to See Complete Forum and Search --> : readonly


shanuragu
08-23-2003, 05:16 AM
Hi

Can I make a list box ie, <select> a read only field??

shara

Fang
08-23-2003, 08:26 AM
I think you mean an input field, select options are read only:

<form action="#">
<input type="text" readonly="readonly" value="odd one out" />
<select name="select1">
<option value="a">apple</option>
<option value="b">banana</option>
<option value="c">cranberry</option>
</select>
</form>

shanuragu
08-24-2003, 08:06 AM
No Readonly to <select> means if I make an option in select field as selected. It should not be changed even if we try to select some other option in the select field.

ex:
<select name="select1">
<option value="a" selected>apple</option>
<option value="b">banana</option>
<option value="c">cranberry</option>
</select>

If a user try to change apple to banana - it should remain as apple.
Is it possible??

shara

Fang
08-24-2003, 08:46 AM
A few options here: (no pun intended ;) )
Add attribute disabled="disabled" to <select> i.e. grayed out, not pretty, but a css could adjust that.
or:
You can see the contents , but can't change the selection

function RestoreDefault(obj) {
for (var i = 0; i < obj.length; i++) {
if (obj.options[i].defaultSelected == true) {
obj.options[i].selected=true;
}
}
}

<form action="#">
<input type="text" readonly="readonly" value="odd one out" />
<select name="select1" onchange="RestoreDefault(this);">
<option value="a" selected="selected">apple</option>
<option value="b">banana</option>
<option value="c">cranberry</option>
</select>
<button type="submit">submit</button>
</form>

or:
Delete/remove the other options usind the DOM.