Connecting Tech Pros Worldwide Forums | Help | Site Map

setAttribute readonly only works in mozilla

Member
 
Join Date: Jul 2008
Location: Indonesia
Posts: 68
#1: Sep 3 '08
hello all, i have this script below
Expand|Select|Wrap|Line Numbers
  1.             var td = document.createElement('td');
  2.             var theInput = document.createElement('input');
  3.             theInput.setAttribute('type', 'text');
  4.             theInput.setAttribute('name', 'codcnourut');
  5.             theInput.setAttribute('size', '3');        
  6.             theInput.setAttribute('value',form.codcnourut.value);
  7.             theInput.setAttribute('readonly','true');
  8.             td.appendChild(theInput);
  9.             row.appendChild(td);
  10.  
i want to make theInput(object/field) become readonly with this script

theInput.setAttribute('readonly','true');

but that works only in mozilla, doesn;t works in IE version 7..
and when i change the setAttribute readonly become like this one below

Expand|Select|Wrap|Line Numbers
  1. theInput.readonly=true;
  2.  
still the same, that script works only in mozilla, not in IE

so any idea??
thanks

Member
 
Join Date: Jul 2008
Location: Indonesia
Posts: 68
#2: Sep 3 '08

re: setAttribute readonly only works in mozilla


ok i have solved the problem

the script must like this one

theInput.setAttribute('readOnly','true');

see...not readonly, but readOnly (with uppercase of 'o')

thanks
kind regards..

maminx
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#3: Sep 3 '08

re: setAttribute readonly only works in mozilla


The JavaScript readOnly property is with a capital O, but setAttribute should've worked with lower-case - see W3C link. IE doesn't follow suit.
Reply


Similar JavaScript / Ajax / DHTML bytes