javascript - Fetching data from many input fields using getElementsByTagName() method -
<!doctype html> <html> <head> <script> function getelements() { var v = document.getelementbyid('view'); var x=document.getelementsbytagname("input"); for(var i=0; i<x.length; i++){ v.innerhtml = x[i].value+"<br>"; } } </script> </head> <body> <input type="text" size="20"><br> <input type="text" size="20"><br> <input type="text" size="20"><br><br> <input type="button" onclick="getelements()" value="how many input elements?"> <p id='view'></p> </body> </html>
this code want fetch values of fields , iterate them below in "p"
tag kept showing me value of last input submit value.
the nature of program me fetch data many inputs elements including file, upload field , submit them server script.
you need change html , javascript following not give button's value(which not needed) :
html:
<input type="text" size="20"><br> <input type="text" size="20"><br> <input type="text" size="20"><br><br> <button onclick="getelements()" value="how many input elements?" >how many input elements?</button> <p id='view'></p>
js:
function getelements() { var v = document.getelementbyid('view'); v.innerhtml = ""; var x=document.getelementsbytagname("input"); for(var i=0; i<x.length; i++){ v.innerhtml += x[i].value+"<br>"; } }
Comments
Post a Comment