Welcome to Webune Web Hosting Support Forums.

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:

first color:
second color:
third color:



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