Badger Badger - 5 months ago 7
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

Just echo it to a javascript variable:

<script type="text/javascript">
    var var1JS = "<?php echo $var1; ?>";
</script>