•
•
•
•
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
![]() |
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:
I have a button, say OK, in the form
Here is my script
how can I use indexing to the text field names and store them in myArray?
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 !
•
•
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation:
Rep Power: 0
Solved Threads: 32
Hi
u can do this with following code.
put all the text boxes in side a div element. and follow the example below:
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
~Mitch Ratcliffe
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
ajax asp cross-browser javascript menu with few lines of code developer development firefox home html internet javascript javascript smooth scrolling scroll smoothly window document position javascript tab menu with rounded corners generator microsoft msdn office prevent javascript menu from getting hidden under flash movies site software sql vista web
- Guidelines before posting (DaniWeb Community Feedback)
- Help needed (C)
- C++ Homework project, need help (simple problem) (C++)
- Noob Help needed for Time problem (C++)
- Need help with IE6 (simple?) problem (HTML and CSS)
- Help needed in simple app while using XML,XSL (XML, XSLT and XPATH)
- guys help needed here please!! (PHP)
- Logitech QuickCam Sphere (Orbit) Tilt Problem (Peripherals)
- pyapal - i am unable to make payment through it - urgent help needed (eCommerce)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: javascript required fields 290 form elements
- Next Thread: Cutting text line


Linear Mode