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
BedrockMission!

Learn More

View all

Sign in to view all badges

Javascript changing mulitple object with sequential number names

Avatar

Avatar
Validate 10
Level 1
shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 1
shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile
shawnFMU
Level 1

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)

Avatar

Avatar
Coach
MVP
radzmar
MVP

Likes

395 likes

Total Posts

2,686 posts

Correct Reply

491 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile

Avatar
Coach
MVP
radzmar
MVP

Likes

395 likes

Total Posts

2,686 posts

Correct Reply

491 solutions
Top badges earned
Coach
Ignite 3
Ignite 1
Validate 1
Give Back 50
View profile
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)

Avatar

Avatar
Validate 10
Level 1
shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile

Avatar
Validate 10
Level 1
shawnFMU
Level 1

Like

1 like

Total Posts

38 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 1
Affirm 1
View profile
shawnFMU
Level 1

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.

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,077 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
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.