Hi, i want to change the hidden elemtn value in the javascript. the name of the filed will have to be formed in the javascript. like this Code: var temp="name"+1; document.[B]temp[/B].value="newname"; i want temp to be replaced by name1 so that the value of name1 field shud change.like this "[B]document.name1.value="newvalue" [/B] " Code: <input type='hidden' name='name1' value'Val'>
Code: var temp="name"+1; // change the value now document.forms[0].elements[temp].value = 'newvalue';
If you want to change the "value" (as you say) of an element named "name1" presumably you just do this: Code: name1.value = 'newvalue' ... <input type="hidden" name="name1" value="oldvalue"> If you are trying to programmatically change from name1 to name2 etc., then you want eval, which allows you to execute a string as code. Code: <script> function changeit() { var newval = "xxxxxxxxxxxxx" for (var i = 1; i <= 5; ++i) eval( 'name' + i + '.innerText="' + newval + '"' ) } </script> <body> <p id=name1>Paragraph 1</p> <p id=name2>Paragraph 2</p> <p id=name3>Paragraph 3</p> <p id=name4>Paragraph 4</p> <p id=name5>Paragraph 5</p> <button onclick=changeit()>Press</button> </body>