Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Javascript changing mulitple object with sequential number names

shawnFMU
Level 3
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
radzmar
Correct answer by
Level 10
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
Magus069
Level 10
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.

shawnFMU
Level 3
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.

radzmar
Correct answer by
Level 10
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