Gentlemen,
I am trying to utilize a javascript variable as the key of a PHP array to echo
out. Notice the javascript variable id
is want I want to use as the key of the PHP array $allNames[]
.
Can I do this without JSON/AJAX? If so please help.
<script type="text/javascript" language="javascript">
$('*[class^="spec"]').mouseover(function(){
var the_class = $(this).attr("class");
var id = the_class.replace("spec", "");
$('#here').html('<?php echo $allNames[id]; ?>'); // here
});
</script>
Many thanks.
echo
commands within javascript. It is entirely possible to inject PHP code in javascript. – khanahk Mar 19 at 1:36json_encode()
is needed. – khanahk Mar 19 at 1:46