You are viewing limited content. For full access, please sign in.

Question

Question

Assign value to a field using JavaScript

asked on March 23, 2014 Show version history

Hi there,

 

I am working on a form that requires me to compute for average in Field1 and assign the corresponding value of the average in Field2. 

 

I am new to JavaScript.  I’ve been looking for a solution to this and have not found anything that works.

 

To give you more details, this is what I am trying to achieve (in simple terms):

                If the average result in Field1 is ‘1’, the value in Field2 is ‘A’

                Else if, the average result in Field1 is ‘2’, the value in Field2 is ‘B’

                Else, the value in Field2 is ‘C’

 

Is there someone here with similar experience? Or maybe anyone who is expert in JavaScript, can give me an advise?

 

Any thoughts is much appreciated.

 

Thanks!

0 0

Replies

replied on March 24, 2014

Is Field 1 in a table? 

 

You will want to look at the calculation in the help page for Forms. That will help you get a basic structure of what you need to do started. Then you will want to add in a variable that will act as a counter that you add '1' to each time you iterate through to the next value. Then at the end, you do some simple math and get your answer. 

 

LINK to Help Page: http://www.laserfiche.com/support/webhelp/laserficheforms/9.0/en-us/forms/#CustomizingYourFormExamples.htm%3FTocPath%3DCreating%20a%20Form|The%20Form%20Designer|Script|_____1

 

To store the value, you will need to do something like the following:

$('#Field2').val( averageValue );

In the example above, 'averageValue' is a variable you have calculated and stored the average into. If you assign a class to the 2nd field though, you can also use the class reference to store the value.

 

 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.