So I have a dynamically created form.
This is a quick run down of what happens.
Page Loads -> jQuery Ajax load page -> Another Ajax loads form: -
<form id="listForm" name="listForm">
-
<input type="text" name="listQty[]" value="0">
-
<input type="checkbox" name="listCb[]" value="php id #">
-
<input type="hidden" name="listTitle[]" value="BlahBlah">
-
(Up to 7 more sets of items currently)
-
</form>
I found this method: - var arrayElements = document.listForm.elements["listQty[]"];
When I try to loop through the values of each element, it just gives me 0 everytime even if I put something else into the text box.
What am I ( and that website... ) doing wrong?
true, but your loop is wrong. for looping through a list you use a standard for() loop, not the for … in loop. further, i refers to the key, which is either a string or a number. - var ele, eleList = document.formList.elements["listQty[]"];
-
for (var i = 0, l = eleList.length; i < l; i += 1) {
-
ele = eleList[i];
-
// …
-
}
9 1591
Not sure about this...Im learning. But if you remove the value 0 from the array. Does it work? I believe that you assigned the array a 0 memory location, but if you remove that value, each time you enter a value in the form it will append an new index.
I'm not sure what you're trying to do but if you're trying to do but if you're trying to return the array of form elements, then you need to stop at .elements. The rest of it will return only one element.
If you are trying to return the value of the element, then you need .value.
Sorry, I'll clarify a little bit. This is what I'm doing: - var eleArray = document.formList.elements["listQty[]"];
-
-
for ( var i in eleArray ) {
-
alert(i.value); // undefined
-
alert(i); // 0
-
}
Well, listQty[] isn't an array. It's the name of a textbox so it has no elements. Just use document.formList.elements.
Going by my last post, am I not?
No, you're not. You're using document.formList.elements["listQty[]"], which will return the textbox, which has no elements. You need to use document.formList.elements, which will return the array of elements in formList.
I would say that would be fine if only "listQty[]" was in the form, but I will have 3 others like the previously metioned. Doesn't form.elements[] if given a string return all the elements matching?
true, but your loop is wrong. for looping through a list you use a standard for() loop, not the for … in loop. further, i refers to the key, which is either a string or a number. - var ele, eleList = document.formList.elements["listQty[]"];
-
for (var i = 0, l = eleList.length; i < l; i += 1) {
-
ele = eleList[i];
-
// …
-
}
I see, I thought you were trying to return all the form elements but you were trying to return all form elements with the same name.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: rhungund |
last post by:
Hey all...
I'm submitting various form variables as arrays, so when I do try to
access them when the form is submitted, i do a split on the variable
and pop it into an array.
for example:...
|
by: Chris Styles |
last post by:
Dear All,
I've been using some code to verify form data quite happily, but i've
recently changed the way my form is structured, and I can't get it to work
now.
Originally :
The form is...
|
by: Geoff Cox |
last post by:
Hello,
I have a series of pages each of which creates an array of values.
How do I keep all the array values until the last page?
Cheers
Geoff
|
by: Olivier BESSON |
last post by:
Hello,
I have a web service of my own on a server (vb.net). I must declare it with
SoapRpcMethod to be used with JAVA.
This is a simple exemple method of my vb source :
...
|
by: aakash |
last post by:
Hello Guys
I am upsizing ms access project to give it a ms sql connectivity
I am having problem in accessing form control values in ms sql function
CREATE FUNCTION "ReportList DateRange"() ...
|
by: judy.j.miller |
last post by:
Does anyone know why i can't access a form element value using dot
notation in firefox, when i'm in a function. Works ok in the body.
I'm trying to do this:
var FarTemp = faren.temp.value;
I...
|
by: DavidB |
last post by:
I am working with a database and I would like to be able to populate
an array at run time and then use the values that were pushed into the
array as criteria for a select query. It seems that this...
|
by: 4Ankit |
last post by:
hey guys i am having trouble changing my array code to include a 'for/
in' structure
the code i am trying to change is below:
<script type="text/javascript">
var contents = new Array(3)
|
by: Nathan Sokalski |
last post by:
I am trying to use the System.Array.ForEach method in VB.NET. The action
that I want to perform on each of the Array values is:
Private Function AddQuotes(ByVal value As String) As String
Return...
|
by: Geethu03 |
last post by:
Hi
i have a array values in hidden format
<form name="form2" method="post" action="test.php">
<input type="hidden" name="date_val" value="<%= date %>">
<input type="hidden" name="name_val"...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |