javascript - Make readonly using getElementByName? -


this question has answer here:

i need make "readonly" text field place javascript code inside external js file. can't modify html directly because page located on remote server..but can interact adding code in external js located on own host.

the html this:

<form id="newunitform" class="left" action="page.php" style="width:600px" method="post"> <fieldset> <ul> <li> <label for="add"> <input type="text" value="" name="add"> <input type="hidden" value="" name="remove"> <input type="hidden" value="105" name="resource_id"> <input type="hidden" value="" name="editid"> </li> </ul> <label for="submit"> </label> <input class="button" type="submit" value="add name" name="submit"> </fieldset> </form> 

i tried several combination such this:

document.getelementbyname('add').readonly=true; 

or this:

var add = document.getelementbyname('add'); add.readonly = true; 

or this:

document.getelementbyid('newunitform'); document.getelementbyname('add').readonly=true; 

but none work.

as rocket hazmat suggests in comment question, should use

document.getelementsbyname('add')[0].readonly=true; 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -