Hello friends,
I need help with a simple program written in HTML using JS.
I have a form which contains a table(using table tags) which has 4 rows and the last column has text boxes. ie. 4*4
What I want to do is take the values from the text boxes and store it in an array in a loop.

here are my 4 text boxes:

<form>
.
.
<table>
.
.
<input type = text name = item1 value = "">
<input type = text name = item2 value = "">
<input type = text name = item3 value = "">
<input type = text name = item4 value = "">
.
.
<table>

</form>

I have a button, say OK, in the form

<input type = button name = "OK button" value = OK onclick = process(this.form)>

Here is my script

<SCRIPT language = javascript>
var myArray = new Array()
function process(f){
  for(var i = 0; i < 3; i++){
   myArray[i] = f.item.value //this is not correct; indexing needed to f.item.value
  }

 for(var i = 0; i < 3; i++){
   document.writeln(myArray[i])
  }
}
</SCRIPT>

how can I use indexing to the text field names and store them in myArray?

Hi
u can do this with following code.
put all the text boxes in side a div element. and follow the example below:

<html>
<head>
 <script language='javascript'>
 function getValues()
 {
	var tc=document.getElementById('allTxt');
	var txtBoxes=tc.getElementsByTagName('input');//txtBoxes is array of input elements inside div:allTxt
	
		var str="";
		var myArray=new Array();
		for(var i=0;i<4;i++)
		{
			//here u can put code to init value of array with data of text box
			str=str+'  '+txtBoxes[i].value;
			myArray[i]=txtBoxes[i].value;
		}
		alert(str);
	
}
 </script>
</head>
<body>
<div id='error'>Hi21 </div>

<div id='allTxt'>
	<input type = text name = item1 value = "" id='t1'>
	<input type = text name = item2 value = "">
	<input type = text name = item3 value = "">
	<input type = text name = item4 value = "">
</div>
<input type=button onClick="getValues();"/>
</body>
<html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.