Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > document.form and array?

Reply
Thread Tools

document.form and array?

 
 
Flyzone
Guest
Posts: n/a
 
      08-28-2007
Hi, i have a little trouble with javascript putting data in a form
html.
I'm parsing an xml file with DomXML (into an hta file), in a loop:

if (i==0) {
document.form.moduleA_0.value = varnameA;
document.form.moduleB_0.value = varnameB;
...
else if (i==1) {
document.form.moduleA_1.value = varnameA;
document.form.moduleB_1.value = varnameB;
...
else if (i==2) {
document.form.moduleA_2.value = varnameA;
document.form.moduleB_2.value = varnameB;
...
And in the html form, many input field idetify by the name moduleA,
moduleB.....
That is very boring.
There is a way to identify them in javascript as 'moduleA_'+i like an
array,
or to write as array? I tried to make a moduleA = new array(10), but i
get many
errors in thml.
Could someone give me some tips? Reading in the old posts didn't help
me (wrong key search?).
Thanks in advance

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      08-28-2007
On Aug 28, 5:21 pm, Flyzone <flyz...@technologist.com> wrote:
> Hi, i have a little trouble with javascript putting data in a form
> html.
> I'm parsing an xml file with DomXML (into an hta file), in a loop:
>
> if (i==0) {
> document.form.moduleA_0.value = varnameA;
> document.form.moduleB_0.value = varnameB;
> ...
> else if (i==1) {
> document.form.moduleA_1.value = varnameA;
> document.form.moduleB_1.value = varnameB;
> ...
> else if (i==2) {
> document.form.moduleA_2.value = varnameA;
> document.form.moduleB_2.value = varnameB;
> ...
> And in the html form, many input field idetify by the name moduleA,
> moduleB.....
> That is very boring.
> There is a way to identify them in javascript as 'moduleA_'+i like an
> array,


Yes (though what you are dealing with is not an array even though you
can access it by index):

var form = document.form;
form['moduleA_' + i] = varnameA;
form['moduleB_' + i] = varnameB;


see :

<URL: http://www.jibbering.com/faq/#FAQ4_39 >


--
Rob

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
if and and vs if and,and titi VHDL 4 03-11-2007 05:23 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57