How to pass JS value in context variable

Avatar

Avatar

jitendrak

Avatar

jitendrak

jitendrak

04-04-2021

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

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

_Manoj_Kumar

MVP

Avatar

_Manoj_Kumar

MVP

_Manoj_Kumar
MVP

04-04-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

Answers (0)