473,378 Members | 1,334 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,378 software developers and data experts.

Edit content of textboxes in an array

k
Hi, I have a problem.

To edit the content of a text box in a form I can use the following
code:

document.getElementById('bugSteps').value = "data"

But I can't figure how to do this in a textbox that belongs to an
array. Puting [] with a number inside doesn't works.
Does anyone know how?
Thanks

Apr 10 '07 #1
5 1925
Lee
k said:
>
Hi, I have a problem.

To edit the content of a text box in a form I can use the following
code:

document.getElementById('bugSteps').value = "data"

But I can't figure how to do this in a textbox that belongs to an
array. Puting [] with a number inside doesn't works.
What do you mean by "a textbox that belongs to an array"?
Post an example of whatever it is that you're talking about.
--

Apr 10 '07 #2
k
On Apr 10, 7:17 pm, Lee <REM0VElbspamt...@cox.netwrote:
k said:
Hi, I have a problem.
To edit the content of a text box in a form I can use the following
code:
document.getElementById('bugSteps').value = "data"
But I can't figure how to do this in a textbox that belongs to an
array. Puting [] with a number inside doesn't works.

What do you mean by "a textbox that belongs to an array"?
Post an example of whatever it is that you're talking about.

--
The textboxes that I want to add text are the next:

1. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>
2. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>

I think that they belong to an array which is defined by the [] that
have in the name.

Thanks

Apr 10 '07 #3
On Apr 11, 5:20 am, "k" <klis...@gmail.comwrote:
>
The textboxes that I want to add text are the next:

1. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>
2. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>

I think that they belong to an array which is defined by the [] that
have in the name.
You better remove '[]' and use number to identify each element's name.
getElementById() is just for id. To get elements in a form, use:
document['name_of_your_form'].elements['name_of_your_elements'].
If you have more than one elements named 'name_of_your_elements', then
you get HTML collection which can be treated like an array.

HTH

Apr 11 '07 #4
Lee
k said:
>
On Apr 10, 7:17 pm, Lee <REM0VElbspamt...@cox.netwrote:
>k said:
>Hi, I have a problem.
>To edit the content of a text box in a form I can use the following
code:
>document.getElementById('bugSteps').value = "data"
>But I can't figure how to do this in a textbox that belongs to an
array. Puting [] with a number inside doesn't works.

What do you mean by "a textbox that belongs to an array"?
Post an example of whatever it is that you're talking about.

--

The textboxes that I want to add text are the next:

1. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>
2. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>

I think that they belong to an array which is defined by the [] that
have in the name.
Nope, not in Javascript. Adding square brackets to a control name
is actually a bad idea. If you want to treat the text boxes as an
array, you just need to give them identical name attributes.

<form name="myForm">
1. <input type="text" size="100" maxlength="125"
name="bugSteps" value=""><br>
2. <input type="text" size="100" maxlength="125"
name="bugSteps" value=""><br>
</form>

Then you can refer to them as in:

var sum=0;
for (i=0;i<document.myForm.bugSteps.length;i++) {
sum += +document.myForm.bugSteps[i];
}


--

Apr 11 '07 #5
k said the following on 4/10/2007 6:20 PM:
On Apr 10, 7:17 pm, Lee <REM0VElbspamt...@cox.netwrote:
>k said:
>>Hi, I have a problem.
To edit the content of a text box in a form I can use the following
code:
document.getElementById('bugSteps').value = "data"
But I can't figure how to do this in a textbox that belongs to an
array. Puting [] with a number inside doesn't works.
What do you mean by "a textbox that belongs to an array"?
Post an example of whatever it is that you're talking about.

--

The textboxes that I want to add text are the next:

1. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>
2. <input type="text" size="100" maxlength="125" name=bugSteps[]
value=""><br>

I think that they belong to an array which is defined by the [] that
have in the name.
Did you try reading the group FAQ? There is an entry that deals
specifically with [] in the name of an input.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Apr 11 '07 #6

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

Similar topics

8
by: Gilles T. | last post by:
How I can get element ID in the edit mode of datagrid control? If I not in the edit mode, there are no problem. <asp:TemplateColumn ItemStyle-CssClass="grid_column_width_3"...
1
by: tim | last post by:
Hello All I am writing an asp app for generating quotes. What I would like to do is allow the user to edit the quote lines without having to open a new page each line. On the quote I have...
3
by: Leo | last post by:
I have a datagrid with the first column as a Edit,Update,Cancel button column. The other 5 columns are template columns. When I click the Edit button in IE6 the row correctly displays the...
2
by: Dave | last post by:
Hi, I'm building a maintenance form for a table and some of the fields are textboxes (i.e name) and some should be dropdowns (i.e country of origin) When a user clicks 'Edit' in the...
1
by: sck10 | last post by:
Hello, I am trying to change a value when a user goes into edit mode on a DetailsView control. I am trying to use the following, but can not figure out how to get to the bound field...
3
by: Slonocode | last post by:
I have some textboxes bound to an access db. I wanted to format the textboxes that displayed currency and date info so I did the following: Dim WithEvents oBidAmt As Binding oBidAmt = New...
6
by: rn5a | last post by:
When the EditCommandColumn in a DataGrid is clicked, all the BoundColumns get replaced by TextBoxes so that users can alter the data. By default, the Text in the TextBoxes are left-aligned. Is...
0
by: programming | last post by:
hi all, here is the php code! i am trying to use to 'edit' hyperlink to edit txt in member.txt. Problem is that it reads the values ok into an array, however when i attempt and update new...
3
by: Joey | last post by:
asp.net 2.0 VS2005 C# In my web app I added a gridview and then manually configured boundcolumns, for an in-session dataset to act as a datasource. Then I added an Edit commandfield. When I...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
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...

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.