Egregi Utenti di HTML.it forum > Lato client > JavaScript.
Su W3Schools ho trovato questo codice:
Codice PHP:
<html>
<body>
<form id="myForm">
Firstname: <input id="fname" type="text" value="Mickey" />
Lastname: <input id="lname" type="text" value="Mouse" />
<input id="sub" type="button" value="Submit" />
</form>
Get the value of all the elements in the form:
<script type="text/javascript">
var x=document.getElementById("myForm");
for (var i=0;i<x.length;i++)
{
document.write(x.elements[i].value);
document.write("
");
}
</script>
</p>
</body>
</html>
e questo output:
Codice PHP:
Firstname: Mickey Lastname: Mouse
Get the value of all the elements in the form:
Mickey
Mouse
Submit
Ho personalizzato (a scopo di esercitazione) il codice in questo modo:
Codice PHP:
<html>
<body>
<form id="myForm">
Firstname: <input id="fname" type="text" value="Mickey" />
Lastname: <input id="lname" type="text" value="Mouse" />
<input id="sub" type="button" value="Submit" />
</form>
Get x in the form:
<script type="text/javascript">
var x=document.getElementById("myForm");
document.write("
");
document.write(x);
</script></p>
Get first element in the form:
<script type="text/javascript">
var x=document.getElementById("myForm");
document.write("
");
document.write(x.elements[0].value);
</script></p>
Get second element in the form:
<script type="text/javascript">
var x=document.getElementById("myForm");
document.write("
");
document.write(x.elements[1].value);
</script></p>
Get third element in the form:
<script type="text/javascript">
var x=document.getElementById("myForm");
document.write("
");
document.write(x.elements[2].value);
document.write("
");
</script></p>
Get all elements in the form:
<script type="text/javascript">
var x=document.getElementById("myForm");
document.write("
");
for (var i=0;i<x.length;i++)
{
document.write(x.elements[i].value);
document.write("
");
}
</script></p>
</body>
</html>
ed ho ottenuto questo output:
Codice PHP:
Firstname:Mickey Lastname: Mouse
Get x in the form:
[object]
Get first element in the form:
Mickey
Get second element in the form:
Mouse
Get third element in the form:
Submit
Get all elements in the form:
Mickey
Mouse
Submit
La mia domanda è questa: come posso manipolare ulteriormente [object]?
Grazie.
Cordiali saluti
icerone80