Q: how to set the readonly attribute to false (IE and Moz)

F

Fred K.

Hi,

I have form text fields that have the attribute readonly. I wish to
use a javascript (invoked by a button on my page) to erase the values
and set
the readonly attribute to false. How do I do this?

Here's what I have that is not working with respect to setting
readonly to false:
function nsfields ( bDefaults ) {

if ( bDefaults == "Yes" ) {
// insert the default values in the fields
document.form1.ns1_hostname.value = 'foo.foobar.com';
document.form1.ns1_hostname.readonly = 'readonly';

} else {
// Blank the fields
document.form1.ns1_hostname.value = '';
document.form1.ns1_hostname.readonly = false;
}
}
 
V

Vjekoslav Begovic

Fred K. said:
Here's what I have that is not working with respect to setting
readonly to false:

document.form1.ns1_hostname.readonly = false;

Use: document.form1.ns1_hostname.readOnly = false;
^
Note the case.

And, BTW, it is safer to write:

document.forms["form1"].elements["ns1_hostname"]
 
D

DU

Fred said:
Hi,

I have form text fields that have the attribute readonly. I wish to
use a javascript (invoked by a button on my page) to erase the values
and set
the readonly attribute to false. How do I do this?

Here's what I have that is not working with respect to setting
readonly to false:
function nsfields ( bDefaults ) {

if ( bDefaults == "Yes" ) {
// insert the default values in the fields
document.form1.ns1_hostname.value = 'foo.foobar.com';
document.form1.ns1_hostname.readonly = 'readonly';

} else {
// Blank the fields
document.form1.ns1_hostname.value = '';
document.form1.ns1_hostname.readonly = false;
}
}

http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-88461592
but
http://www.robinlionheart.com/stds/html4/results.xhtml#readonly_text_only

DU
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top