Edit content of textboxes in an array

K

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
 
L

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.


--
 
K

k

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
 
C

Cah Sableng

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
 
L

Lee

k said:
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;
}




--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,681
Members
48,796
Latest member
Greg L.

Latest Threads

Top