Is there any way I can save some info in a php variable and access it in Javascript? Or something similar to that?
PHP to Javascript
let the php code print a javascript that can save the php variable value to javascript var.
this php code stores value of php variable $php_var = ['junk':string] to javascript variable ,java_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.
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
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:
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.
Thanks, Codeman
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.
Try adding single quotes:
BTW: your pastebin has expired.
"How long should your post be retained?" -> "forever"
| Code: |
|
onclick="showAns('<? echo $id; ?>');" |
BTW: your pastebin has expired.
"How long should your post be retained?" -> "forever"
http://www.javascriptkit.com/script/script2/jstohtml.shtml go and change php or html there (it does work with PHP ok).
| codeman wrote: | ||
Ok, so I got that working but now I'm having problems getting my onclick to actually call the js functions.
|
Add javascript: before the function name.
| Code: |
| ... onclick="javascript:alert('Hello?')" |
