Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Using SetValue() for java script value

Hi Team,

I would like to set a value in my merge field dynamically could you please provide me some assistance for the same.

For example,

 var x =1; 


x is my dynamic value and would like to set its value in my merge field I am being able to set static value as below:
 [%SetValue(mymergefield, 1) %] 

However would like to set value dynamically as below:
 [%SetValue(mymergefield, x) %] 


Regards,
Samarth
asked Feb 16, 2016 by samarth

1 Answer

0 votes
You could set a variable and use SetValue within some Perl script.  Something like this where the variable x is being set to the value of Q1:

[% Begin Unverified Perl
my $x = GETVALUE("Q1")
{SETVALUE("mymergefield", $x))}
End Unverified %]
answered Feb 16, 2016 by Jay Rutherford Gold (25,635 points)
Thanks Jay!

However my requirement is slightly different, the solution which you shared will only work within the scope of unverified perl. What I am loking for is way to transfer values from javascript/jquery variable which is changing on existing page and once respondent submit the page I would like to send the last value to database so that I may use it on net page of the link.

Hope i am being able to share my concern!

Looking forward for your views below is the code

var x= 0;
$(':input').change(function(){
x = $('this').val();
});

[%SetValue(mymergefield, x) %]


Cheers!
Samarth
Unfortunately I'm not sure if the Set Value command can be incorporated into javascript.  You may want to check with Support.
...