How to pass JS value in context variable | Community
Skip to main content
Level 2
April 4, 2021
Solved

How to pass JS value in context variable

  • April 4, 2021
  • 1 reply
  • 3149 views

Hi All,
I have the below query.

i have created a web form using html activity (not V5) , in the web form I am collecting some data in text form, now i want to store this value in context variuable.

For eg 

Context variable created in web application with name : my_purchase_number

In the web form there is a input text field where user enters the purchase number stired in JS variable inside html, let's say variable name is purchase_number.

When user clicks on submit button i want the value of context variable ctx.vars.my_purchase_number = purchase number.

Any help on how to achieve this is highly appreciated.

 

Regards

Jay

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Manoj_Kumar

Hello @jitendrak 

 

You will have to create a javascript function to do this. 

 

Here is an example

<script> function updateCtxValues(){ var purchaseNumber=document.getElemebtById('purchase_number').value; document.controller.setValue('/ctx/vars/my_purchase_number', purchaseNumber); } </script>

You will have to call this function on the form submission by onclick event

<input type="button" onclick="updateCtxValues()" value="submit">

Also, make sure your purchase number input has an id attribute of value "purchase_number"

 

Let me know if that works.

Thanks

1 reply

Manoj_Kumar
Community Advisor
Manoj_KumarCommunity AdvisorAccepted solution
Community Advisor
April 4, 2021

Hello @jitendrak 

 

You will have to create a javascript function to do this. 

 

Here is an example

<script> function updateCtxValues(){ var purchaseNumber=document.getElemebtById('purchase_number').value; document.controller.setValue('/ctx/vars/my_purchase_number', purchaseNumber); } </script>

You will have to call this function on the form submission by onclick event

<input type="button" onclick="updateCtxValues()" value="submit">

Also, make sure your purchase number input has an id attribute of value "purchase_number"

 

Let me know if that works.

Thanks

Manoj     Find me on LinkedIn
jitendrakAuthor
Level 2
April 4, 2021
Thanks Manoj, somehow it's still not working