Expand my Community achievements bar.

SOLVED

Javascript changing mulitple object with sequential number names

Avatar

Level 3

I wrote this code for a check box object that, once clicked, will check other box objects at once:

javascript, change:

if (this.rawValue == 1) {

S1.rawValue = 1;

S2.rawValue = 1;

}

it works.

Then I wanted to simplify the script by renaming my objects and tried this:

if (this.rawValue ==1) {

S[*].rawValue = 1;

}

doesn't work... T_T

syntax error? have to do a variable? scratching my head. help.

Many thanks in advance!

1 Accepted Solution

Avatar

Correct answer by
Level 10

This script should do the trick.

var iSel = this.rawValue,

oFields = this.resolveNodes("#field[*]");

for (var i = 0; i < oFields.length; i += 1) {

oFields.item(i).rawValue = iSel === 1 ? 1 : null;

}

View solution in original post

3 Replies

Avatar

Level 10

Hi there,

to do this, you must use resolveNode to apply changes to all different objects.

This approach may be accepted if you use FormCalc instead of JavaScript, but syntax would be different.

To use the resolveNode method, you should try it this way :

This should do the trick.

I hope this help.

Avatar

Level 3

Thank for checking!

Unfortunately, I'm getting a syntax error on the 3rd line.

Also, no idea what I'm reading..oLen.. I++... I'm not a programmer by any stretch.

None the less, I'm looking up resolve Nodes now.

Avatar

Correct answer by
Level 10

This script should do the trick.

var iSel = this.rawValue,

oFields = this.resolveNodes("#field[*]");

for (var i = 0; i < oFields.length; i += 1) {

oFields.item(i).rawValue = iSel === 1 ? 1 : null;

}