Javascript changing mulitple object with sequential number names

shawnFMU

01-09-2017

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!

Accepted Solutions (1)

Accepted Solutions (1)

radzmar

MVP

04-09-2017

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;

}

Answers (2)

Answers (2)

shawnFMU

01-09-2017

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.

Magus069

MVP

01-09-2017

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.