Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
181
rated 0 times [  184] [ 3]  / answers: 1 / hits: 23561  / 15 Years ago, mon, january 18, 2010, 12:00:00

How do I create the following markup using JavaScript's document.createElement function?



<input type=hidden value= id= />

More From » html

 Answers
5

Here is some code to create your input box:



var element = document.createElement('input');
element.type = 'hidden';
element.value = '';
element.id = '';


To add it to a <form> with id=myform you could do this:



var myform = document.getElementById('myform');
myform.appendChild(element);


FYI: Your <input> doesn't have a name attribute. If you're planning on submitting it as part of a form and processing it on the server side, you should probably include one.


[#97808] Thursday, January 14, 2010, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
felixa

Total Points: 180
Total Questions: 113
Total Answers: 108

Location: Palau
Member since Sat, Aug 21, 2021
3 Years ago
;