FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

PHP to Javascript

 


codeman
Is there any way I can save some info in a php variable and access it in Javascript? Or something similar to that?
afracsass
let the php code print a javascript that can save the php variable value to javascript var.
Code:

<?php

$php_var = 'junk';

echo '
<script language=javascript>
var java_var = "'.$php_var.'";
</script>
';

?>


this php code stores value of php variable $php_var = ['junk':string] to javascript variable ,java_var.
codeman
Ok, so I got that working but now I'm having problems getting my onclick to actually call the js functions. Here's my code:

here

in the line
Code:
... onclick="alert('Hello?'); showAns(1)"

the alert shows up but showAns (even by itself) doesn't work... I'm REALLY rusty at JS but I'm pretty sure that a call:
Code:
... onclick="showAns(<? echo $id; ?>);"

should call the function showAns with the id as the parameter... right?

if anyone has any suggestions on anything that doesn't pertain to my question I would also like to hear that. Very Happy Thanks, Codeman
Aredon
Try adding single quotes:
Code:

onclick="showAns('<? echo $id; ?>');"


BTW: your pastebin has expired.
"How long should your post be retained?" -> "forever"
dwcnps
http://www.javascriptkit.com/script/script2/jstohtml.shtml go and change php or html there (it does work with PHP ok).
Nyizsa
codeman wrote:
Ok, so I got that working but now I'm having problems getting my onclick to actually call the js functions.
Code:
... onclick="alert('Hello?')"

Add javascript: before the function name.
Code:
... onclick="javascript:alert('Hello?')"
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.