Badger Badger - 1 year ago 63
HTML Question

Referencing a defined html variable in JS

My index.php page includes a config.php file, which returns an array that I have defined some variables in by using "define('var1' , 10)".

I am trying to validate my forms input, but I can't figure out how I can reference var1 from within the JS function. What is the easiest way to do this?

Answer Source

Just echo it to a javascript variable:

<script type="text/javascript">
    var var1JS = "<?php echo $var1; ?>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download