readonly

liunx

Guest
Hi<br />
<br />
Can I make a list box ie, <select> a read only field??<br />
<br />
shara<!--content-->I think you mean an input field, select options are read only:<br />
<br />
<form action="#"><br />
<input type="text" readonly="readonly" value="odd one out" /><br />
<select name="select1"><br />
<option value="a">apple</option><br />
<option value="b">banana</option><br />
<option value="c">cranberry</option><br />
</select><br />
</form><!--content-->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.<br />
<br />
ex:<br />
<select name="select1"><br />
<option value="a" selected>apple</option><br />
<option value="b">banana</option><br />
<option value="c">cranberry</option><br />
</select><br />
<br />
If a user try to change apple to banana - it should remain as apple.<br />
Is it possible??<br />
<br />
shara<!--content-->A few options here: (no pun intended ;) )<br />
Add attribute disabled="disabled" to <select> i.e. grayed out, not pretty, but a css could adjust that.<br />
or:<br />
You can see the contents , but can't change the selection<br />
<br />
function RestoreDefault(obj) {<br />
for (var i = 0; i < obj.length; i++) {<br />
if (obj.options.defaultSelected == true) {<br />
obj.options.selected=true;<br />
}<br />
}<br />
}<br />
<br />
<form action="#"><br />
<input type="text" readonly="readonly" value="odd one out" /><br />
<select name="select1" onchange="RestoreDefault(this);"><br />
<option value="a" selected="selected">apple</option><br />
<option value="b">banana</option><br />
<option value="c">cranberry</option><br />
</select><br />
<button type="submit">submit</button><br />
</form><br />
<br />
or:<br />
Delete/remove the other options usind the DOM.<!--content-->
 
Back
Top