Hi AppGini'ers
I have a form, say "myform", which contains a hidden field quantityMax
I have a validation script, say myform-dv.js (based on the UDEMY lessons)
I see that there is an array in the rendered form containing the value I want, within script tags - var data = {quantityMin: "200", quantityMax: "500"};
How can I pass the data() value to the validation function in myform-dv.js file?
Alternatively,
I have a hook file, say myform.php (which has a value for the $quantityMax field, taken from the DB)
How can I pass the $quantityMaxvar value in php to the JS script?
TIA, James
Getting JS var from rendered page to JS validate script
Re: Getting JS var from rendered page to JS validate script
Hi,
I'm not sure if you can directly get the variable. But you can retrieve in myform-dv.js the part that contains the relevant data by
e.g.
then you get a string that you need to manipulate to your needs.
Hope that gives a starting point.
I'm not sure if you can directly get the variable. But you can retrieve in myform-dv.js the part that contains the relevant data by
e.g.
Code: Select all
$j("script:contains('var data = {quantityMin:')").text()
Hope that gives a starting point.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.
Re: Getting JS var from rendered page to JS validate script
Yes it does pbottcher, thanks.James