How To Make Array In Javascript
RegisterLogin
How To Make Array In Javascript
Post Description: Making Array In Javascript This Post Will Show You How You Can Make Arrays In Your Javascript Using Our Example Code And Will Explain How To Use The Javascript Code To Make An Array From The Fields In A Form Using Input Tags And Values Of Elements
Tags: How, To, Make, Array, In, Javascript
This Post Was Posted On Dec 27, 2009 By Webune Support #2957
Post Description: Making Array In Javascript This Post Will Show You How You Can Make Arrays In Your Javascript Using Our Example Code And Will Explain How To Use The Javascript Code To Make An Array From The Fields In A Form Using Input Tags And Values Of Elements
Tags: How, To, Make, Array, In, Javascript
This Post Was Posted On Dec 27, 2009 By Webune Support #2957
How To Make Array In Javascript by Webune Support
We provide web hosting for many websites. many customer use javascript on their websites so we are going to show you today how you can create an array using javascript in your html.
If you are familiar with arrays, you know that each array element contains a value so for example, lets say that i have a web form and each input field creates an element on my array, so you can use this example code to see how it works:
JAVASCRIPT CODE:
<script type="text/javascript" language="javascript">
function submitted(len){
for ( var i=0; i<len; i++ ){
alert(document.getElementById(i).value);
}
}
</script>
Colors:
<form name='myform'>
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(3);"/>
</form>
as you can see from the code above, i am using a for loop to display the values of each field by using a popup alert window.
try it:
Colors:
more advanced: if you feel confortable using this script, we can take it to the next level. as you can see in the code, the submit button has an onclick() which tells your function you have 3 elements in the submitted() function, but how about intead, let javascript determine how many elements there are in the array, visit our next tutorial to find out how:
Count Number Of Elements In An Array
Leave Your Comments
Related Pages: [Add Your Website]
Post New Topic
hami
#3252 1
i was wondering how to build a array in javascript but now that you showed me - it works, i tried it
thank you sir
cheers from india!
thank you sir
cheers from india!
Jan 14, 2010 Reply Report abuse
©2012 Webune Forums - Wed Dec 19, 2012 10:20 am
Powered by: Webune Forums V3
Powered by: Webune Forums V3