- Forums
- Javascipt
- Wow to Use getElementById() in Javascript
This Page Will Teach You A With Some Example About Using Javascript Get Element By Id Function So You Can Get The Value Of An Element In A Form [2205], Last Updated: Mon Jun 24, 2024
Webune Tutorials
Sun Jan 10, 2010
0 Comments
386 Visits
document.getElementById('field').value
Welcome to Webune Forums.
Webune Offers Web Hosting for many sites.
One of the cool features about websites is the ability to use Javascript on your webpages.
if you are familiar programming in javascript or are new to javascript, perhaps you might find this short tutorial on about using javascript getElementById() function.
this is an example script you can use to see how you can get the value of a field using getElementById...
<script type="text/javascript" language="javascript">
function submitted(){
var form = document.myform2
for (i = 0; i < form.elements.length; i++) {
alert(document.getElementById(i).value);
}
}
</script>
Colors:
<form name="myform2">
first color: <input type="text" id="0" value="red"><br />
second color: <input type="text" id="1" value="blue"><br />
third color: <input type="text" id="2" value="green"><br /><br />
<input type="button" value="send" onclick="submitted();"/>
</form>