Pass php variables to external javascript -
this question has reply here:
how pass variables , info php javascript? 13 answershow can pass php variables external javascript file? found lot of questions regarding can't figure out anyhow.
in html file have link
<script type="text/javascript" src="myscript.php"></script>
this myscript.php file have been trying output javascript file:
<? header("content-type: text/javascript"); ?> $(document).ready(function() { $("#validate_form").validate({ rules: { page_title: "required", seo_url: "required" }, messages: { page_title: "<?=$page_title?>", seo_url: "<?=$seo_url?>" } }); });
append them using query string:
<script type="text/javascript" src="myscript.php?page_title=whatever&seo_url=whatever"></script> <? header("content-type: text/javascript"); ?> $(document).ready(function() { $("#validate_form").validate({ rules: { page_title: "required", seo_url: "required" }, messages: { page_title: "<?=$_get['page_title'];?>", seo_url: "<?=$_get['seo_url'];?>" } }); });
php javascript
No comments:
Post a Comment