I’m creating a dynamic form with javascript which contains a drop down list and an input text as below :
$(document).ready(function() {
document.write("<FORM>");
document.write("<SELECT NAME='SelectMenu'>");
for (var i = 1; i <= 3; i++)
document.write("<OPTION>" +"one"+"</OPTION>");
document.write("<OPTION>" +"two"+"</OPTION>");
document.write("<OPTION>" +"three"+"</OPTION>");
document.write('</SELECT>');
document.write("<br>Entry <input type='text' name='myInputs[]'>");
document.write("<button onClick="ChoixDeQuestion()">Show</button>");
document.write('</FORM>');
});
The problem here is that I can’t access those fields since they don’t even exist in the source code of the page.
I want to get the entered text value and the selected item of the list.
So Any idea please!!
Thanks
Using
document.writeshould be avoided. Its not a good practice.You are using jQuery and its very easy to dynamically create elements in jQuery.
You can do something like this,
jsFiddle
If you know a basic jQuery, everything is self explained, but do let me know if something bothers you 🙂