473,503 Members | 2,166 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

get and put value from a dynamicly created textfield

Hi,

The thing I want to do, is to get - change and put content from text
fields that is dynamically created.
I use PHP to create the form that have textfields in it. The number of
textfields vary.
The name of each field is text2 - text3 - text4 and so on.

So in javascript I want to get the content in text2. And that without
writing:
value = parseInt(document.form1.text3.value);

I want to put this into a for loop and do something like this
for(i=0;i<numfield;i++)
{
value[i] = parseInt(document.form1.["text"+i].value);

}

Is this posible in javascript, and if so what is the syntax?

Regards,

Sindre
Jul 23 '05 #1
3 1681


Pål Sindre Hiåsen wrote:

I want to put this into a for loop and do something like this
for(i=0;i<numfield;i++)
{
value[i] = parseInt(document.form1.["text"+i].value);


You need to drop that dot that is you need to use
document.form1["text" + i].value

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
On Sat, 21 May 2005 16:22:15 +0200, Martin Honnen <ma*******@yahoo.de>
wrote:


Pål Sindre Hiåsen wrote:

I want to put this into a for loop and do something like this
for(i=0;i<numfield;i++)
{
value[i] = parseInt(document.form1.["text"+i].value);


You need to drop that dot that is you need to use
document.form1["text" + i].value


Thanks!

Sindre
Jul 23 '05 #3
Pål Sindre Hiåsen wrote:
[...] Martin Honnen [...] wrote:
Pål Sindre Hiåsen wrote:
I want to put this into a for loop and do something like this
for(i=0;i<numfield;i++)
{
value[i] = parseInt(document.form1.["text"+i].value);

parseInt() by default also parses hexadecimal (with leading `0x') and in
some implementations deprecated octal (with leading zero) values. If you
don't want that, pass a second operand to indicate the target base:

value[i] = parseInt(..., 10);

Parsing any non-decimal value then will result in `NaN' which evaluates
to `false' in a boolean expression.
You need to drop that dot that is you need to use
document.form1["text" + i].value


The both standards compliant and downwards compatible way is

document.forms["form1"].elements["text" + i].value

You should assign overly long and mroe often used references to a variable:

var fe = document.forms["form1"].elements;
if (fe["text" + i])
{
... fe["text" + i].value ...
}

And if you pass the reference to the handling method, referencing becomes
much easier:

....
<head>
...
<meta http-equiv="Content-Script-Type" content="text/javascript">
...
</head>

<body>
...
<form action="..." ...>
<div>
...
<script type="text/javascript">
function handleMe(f)
{
var fe;
if (f && (fe = f.elements))
{
...
if (fe["text" + i])
{
... fe["text" + i].value ...
}
...
}
}

document.write('<input ... onclick="handleMe(this.form);">');
</script>
...
</div>
</form>
...
</body>
PointedEars
Jul 23 '05 #4

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

Similar topics

1
16605
by: LRW | last post by:
Below is some of the code I'm using. I have a PHP page generating a list of items. I've made it so that each one has a radiobutton with a unique value. You can click on the radiobutton and it will...
13
9585
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
2
11237
by: Vern | last post by:
I created a table in a dataset that contains multiple columns. I attached a combo box to that table. Now I'm doing something wrong with trying to retrieve the value of the third column of the...
2
1686
by: Wayne Sepega | last post by:
I have the following Code: foreach (MyClass d in myClassCollection) { curRadioBtn = new RadioButton(); curRadioBtn.Text = d.ToString(); curRadioBtn.GroupName = "Contact"; curRadioBtn.ID =...
1
5906
by: platostoteles | last post by:
Hallo NG, I am new to JavaScript and would really appreciate any help to solve my problem. I am using the blow code in my form to validate form fields. What I would like to accomplish is that...
1
1983
by: saikatbose2005 | last post by:
Hi, Ineed some help from anyone regarding an issue I'm facing. I've created an image dynamically on clicking a button. What I inetend to do is when I click on the created image it will popup a...
1
1918
by: macintoshhondo | last post by:
Hi ! i am a newbie and dont know javascript much. what i really need is a simple javascript code that can insert number in the value section of the different forms from the one form. FORM 1:...
1
3399
by: prathna | last post by:
Hi all, I would like to know how to pass a form bean value to javascript function to perform some validation.. I have a dropdown list and a textfield. I have created the dropdown list using...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7008
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7467
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.