0

Is there a Javascript way how to simple set multiple variables like in PHP?

example in PHP:

<?php
$var1 = 'first code or text';
$var2 = 'second code or text';
...
?>

and called enywhere simply by

<?php echo $var1; ?>

I founded for Javascript only "innerHTML" approach, associated with elements/id tags

<script>
var el = document.getElementById('variable1');
el.innerHTML = 'taste text';
</script>

with

<span id="variable1"></span>

Thanks

1 Answer 1

0

It is ok to do that

<script type="text/javascript">
var var1="first code or text";
var var2="second code or test";
</script>

Then you display it on your page by document.write() function which is in the core of javascript you have to call it at the place you want like this

<script type="text/javascript">
document.write(var1);
</script> 
Sign up to request clarification or add additional context in comments.

1 Comment

sadly cant be directly inserted into html code like php... <a href="http://"><script>document.write(var1);</script></a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.