473,657 Members | 2,294 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(docume nt.form1.text3. value);

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

}

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

Regards,

Sindre
Jul 23 '05 #1
3 1699


Pål Sindre Hiåsen wrote:

I want to put this into a for loop and do something like this
for(i=0;i<numfi eld;i++)
{
value[i] = parseInt(docume nt.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*******@yaho o.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<numfi eld;i++)
{
value[i] = parseInt(docume nt.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<numfi eld;i++)
{
value[i] = parseInt(docume nt.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="handle Me(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
16636
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 change the value of a text field to the value of the radiobutton--all that works fine! Now, I need to also have it populate a textfield with the value of a textfield in the row that's selected. I can make unique field names, no problem. I...
13
9607
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 assigned to a variable and output using document.write. (Note, there is no submit button or other form elements. Basically
2
11292
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 selecteditem. The datatable row contains the following columns, (ProductCd, Description, ProductType), the displaymember is Description, and the valuemember is ProductCd. I know how to get the values of the displaymember and valuemember, but how...
2
1691
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 = d.Name; curRadioBtn.EnableViewState = true; curRadioBtn.CheckedChanged += RadioButton_CheckedChanged;
1
5920
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 if when the list/menu (attribute6) value is "Ja" then to make the TextField Pas Nr (attribute4) required. And if when the list/menu (attribute6) value is "Nee" to make the TextField Pas Nr (attribute4) not required.
1
1996
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 calendar. But the problem is that when I click on the button to create the image it automatically opoup the calendar before creating the image and giving an error "not Implemented" at newimg.onclick. I'll really appreciate if anyone can help here...
1
1934
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: <form> <input type="text" name="textField" size="20"><br> </form> In the "TextField " of Form 1 i type any number and let the number be 100. Now what i really want is that in Form 2 : Textfield should be 100 that is just like that of form 1. In...
1
3409
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 html:select tag & the textfield using html:text tag.I have a corresponding formbean with a get/set methods to get/set the dropdown value selected and also for the textfield.now i have onchange attribute in which i call a javascript function. now how...
0
8407
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8319
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8837
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8512
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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 we have to send another system
2
1969
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.