473,383 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Referencing form elements

<input type='text' name='foo1bar' />
<input type='text' name='foo2bar' />

If I wanted to set a value for both of these in a for loop how would I
go about referencing these elements with a changing value... that is:

What would be functionally equivalent but actually working of this:

for(i = 1;i <= 2;i++) {
document.formfromabove.foo+i+bar.value;
}

The 'foo+i+bar' part obviously doesn't work. What would I have to do to
actually achieve such a thing?

Oct 15 '06 #1
5 2502
If the above request isn't possible.

How can I append HTML code to an element without resetting it.

If you innerHTML .= foobar or innerhtml = innerhtml + foobar and you
have forms in the element you are changing the forms are reset.
Ultimately I'm trying to either replace the values after the new code
is added or find a way to append to the end without resetting the form
values.

Oct 15 '06 #2
VK

th*****@gmail.com wrote:
What would be functionally equivalent but actually working of this:

for(i = 1;i <= 2;i++) {
document.formfromabove.foo+i+bar.value;
}
for(var i = 1; i <= 2; i++) {
document.forms['formName'].elements['foo'+i+'bar'].value = i;
}

Oct 15 '06 #3
VK wrote on 15 okt 2006 in comp.lang.javascript:
>
th*****@gmail.com wrote:
>What would be functionally equivalent but actually working of this:

for(i = 1;i <= 2;i++) {
document.formfromabove.foo+i+bar.value;
}

for(var i = 1; i <= 2; i++) {
document.forms['formName'].elements['foo'+i+'bar'].value = i;
}
===

with document.forms['formName'] {
.elements['foo1bar'].value = 1;
.elements['foo2bar'].value = 2;
};

===

with document.forms['formName'] {
i=1;while (i<=2)
.elements['foo'+i+'bar'].value = i++;
}

===

var f = document.forms['formName'].elements;
f['foo1bar'].value = 1;
f['foo2bar'].value = 2;

not tested ;-(

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Oct 15 '06 #4
VK
Evertjan. wrote:
with document.forms['formName'] {
.elements['foo1bar'].value = 1;
JavaScript doesn't have (unfortunately, IMHO) default object accessor
shortcut, so this code will lead to a syntax error.

<kidding>
Hbu... Nuu... Funzr... !@#$%... Lbh qba'g xabj wninfpevcg!... Bu!...
(Ohg jr funyy fxvc ba guvf hfryrff Unyybjrra fbhaqgenpx :-)
</kidding>

Oct 15 '06 #5
th*****@gmail.com wrote:
<input type='text' name='foo1bar' />
<input type='text' name='foo2bar' />
If I wanted to set a value for both of these in a for loop how would I
go about referencing these elements with a changing value... that is:
for(i = 1;i <= 2;i++) {
document.formfromabove.foo+i+bar.value;
}
The 'foo+i+bar' part obviously doesn't work. What would I have to do
to actually achieve such a thing?
http://www.javascripttoolbox.com/bes...#squarebracket

This was written specifically for questions like this!

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Oct 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: phpcode | last post by:
I have a javascript function as follows: function myfunction(formName,formField) { parseInt(document.formName.formField.value) +=1; } Then I can call the function when needed like this: ...
5
by: Gregor Rot | last post by:
Hi, if i have this code: <form><input type=text name="id1"></form> then with javascript i can reference this with this.form.id1, how can i reference something like this: <table> <tr...
10
by: Data Guy | last post by:
In my approach to validation for widgets, i write javascript functions. At the end of the document, inside the form, i invoke the function as <FORM NAME="testit"> <INPUT TYPE="TEXT" VALUE="2"...
6
by: jstaggs39 | last post by:
I want to create a Dcount and an If...Then...Else statement to count the number of records in a table based on the date that is entered to run the form. The If....Else statment comes in because if...
10
by: Macka | last post by:
A few pieces of information first: * I have a class called Folder which represents a row of data in a database table. The data access side of things is not an issue. * The table has a parent...
2
by: Steve | last post by:
I have a .NET windows program that has a VB.NET component and a C# component. The VB component contains the form and handles all the UI stuff. The C# component drives the engine that actually does...
12
by: Mark Broadbent | last post by:
Hi guys, just going through remoting at the moment and a couple of questions relating to .net in general has surfaced. Firstly I have seen in the designer that for the namespace and many of its...
4
by: darrel | last post by:
I have a contact form that a person submits to the server. In ASP, you'd make a page, post the form to another page, which would grab the values and do somethign with them. in ASP.NET, it...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
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,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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$) { } ...
0
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...
0
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
0
BarryA
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...
1
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.