-1

I have some variables in Javascript if statement which capture the values in a form. A check box and a couple of drop downs. Is there any way I can make the variables a bit dynamic? For example, if the user decides to select a different option then the value updates? At the moment it only captures what is currently selected on page load.

if(document.URL.indexOf("page") >= 0 && document.cookie.search('myCookie') < 0){ 


var productvalue = document.querySelector('input[name=product]:checked').value;

var amount = document.getElementById("frm-amount");
var amountValue = amount.options[amount.selectedIndex].value;

var term = document.getElementById("frm-term");
var termValue = term.options[term.selectedIndex].value;
SamualG
  • 35
  • 1
  • 6
  • Possible duplicate of [JavaScript - Getting HTML form values](https://stackoverflow.com/questions/3547035/javascript-getting-html-form-values) – hsz Jul 31 '18 at 09:06

1 Answers1

0

You need to add the event listeners.

For the select box, you need to add the change event listeners and for the input fields, you could go with keyup (or again, change).

Also, you need to provide a bit more of your HTML code for a more refined solution.

But, I hope that gives a brief idea.

Adictonator
  • 138
  • 11