User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 430,095 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,171 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 637 | Replies: 1
Reply
Join Date: Dec 2007
Location: INDIA
Posts: 32
Reputation: abhi_elementx is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
abhi_elementx's Avatar
abhi_elementx abhi_elementx is offline Offline
Light Poster

Help @@Help needed with simple problem@@

  #1  
Jan 24th, 2008
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?
PEACE !
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 32
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Solution Re: @@Help needed with simple problem@@

  #2  
Jan 24th, 2008
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>
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:53 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC