Getting JS var from rendered page to JS validate script

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
User avatar
jmcgov
Posts: 27
Joined: 2018-12-19 01:31

Getting JS var from rendered page to JS validate script

Post by jmcgov » 2019-07-10 17:35

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

pböttcher
AppGini Super Hero
AppGini Super Hero
Posts: 488
Joined: 2018-04-01 10:12

Re: Getting JS var from rendered page to JS validate script

Post by pböttcher » 2019-07-13 22:06

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.

Code: Select all

$j("script:contains('var data = {quantityMin:')").text()
then you get a string that you need to manipulate to your needs.

Hope that gives a starting point.

User avatar
jmcgov
Posts: 27
Joined: 2018-12-19 01:31

Re: Getting JS var from rendered page to JS validate script

Post by jmcgov » 2019-07-15 23:31

Yes it does pbottcher, thanks.James

Post Reply