Expand my Community achievements bar.

SOLVED

Accessing form array objects through javascript

Avatar

Level 1

I have what I hope is an easy question that I've been beating my head on for days....

Say I have a form with multiple fields of the same name - let's call the fields recordedHours.

Adobe assigns an index to each instance of the field, so we'll have recordedHours[0], recordedHours[1]... recordedHours[30]

Now I need to set and get the values using Javascript, so something like:

for (i=0; i<=30; i++)

{

  var hrs = this.recordedHours[i].rawValue;

}

This doesn't work. Neither does a full reference: form1.timeform.recordedHours[i].rawValue

or getElement: this.getElement("recordedHours",i)

or dot notation: form1.timeform["recordedHours"].i.rawValue (syntax error, as i, when converted to numeric gives an illegal object/element identifier)

I have tried every way I can possibly think of to get and set the values through Javascript and I've searched high and low on the web but can't find anything - I know I'm probably suffering from SUS (Stupid User Syndrome), but can anyone help me out here?

Cheers,

Marty.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

The issue is that you have to resolve the expression to be able to get the right index so you can use the xfa.resolveNode syntax. This allows you to pass in a string and that gets interpretted for you . So the syntax woudl be:

for (i=0;i<=30;i++){

     var hrs = xfa.resolveNode("form1.Page1.recordedHours[" + i + "]").rawValue

}

Hope that helps

Paul

View solution in original post

2 Replies

Avatar

Correct answer by
Former Community Member

The issue is that you have to resolve the expression to be able to get the right index so you can use the xfa.resolveNode syntax. This allows you to pass in a string and that gets interpretted for you . So the syntax woudl be:

for (i=0;i<=30;i++){

     var hrs = xfa.resolveNode("form1.Page1.recordedHours[" + i + "]").rawValue

}

Hope that helps

Paul

Avatar

Level 1

Thanks Paul,

That's great - saves me a LOT of coding!

Cheers,

Marty.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----