Forum Moderators: open

Message Too Old, No Replies

How to include PHP variables into Javascript?

         

toplisek

11:35 am on Nov 21, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I have jQuery like:
jQuery(".forms_1_1").validate({

rules: {
inputname1: {
required: true,
},


or
inputname1: {
required: "Requested field!.",
},

Is it technically possible to add
1. PHP variable like $_SESSION and
2. Smarty variable into Javascript like {$global.variable1}

inputname1 is value for each variable (PHP, Smarty).

Need help how to include variable values into Javascript code.

Demaestro

5:30 pm on Nov 21, 2014 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Typically I will write the PHP variable values that I need into the markup of the page.

You can use hidden fields or you can add a tag and add the fields as attributes. You then you use JQ to get the values from the markup.

<span id="system_vars" var1="val1" var2="val2" />
Or
<hidden class="system_vars" name="var1" value="val1" />
<hidden class="system_vars" name="var2" value="val2" />