469,327 Members | 1,262 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

how to pass php value to javascript function?

hii friends..

i am in need of a coding.. can u help me??

how to pass a php variable as an argument to javascript function?? is there any possible ways???
Feb 16 '09 #1
7 12675
6,050 Expert 4TB
Echo your variable into the javascript..

Expand|Select|Wrap|Line Numbers
  2. doFunction("<?php echo $var; ?>");
  4. function doFunction(arg)
  5. {
  6.     // ...
  7. }
Feb 16 '09 #2
can u explain how to call this function ?? within php coding?? or in onSubmit, onclick events??
Feb 16 '09 #3
6,050 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="doFunction('<?php echo $var; ?>');">Click</a>
Feb 16 '09 #4
5,058 Expert 4TB
@sweetline priya
The main thing to realize here is that PHP is a server-side language, while JavaScript is a client-side language.

They can not directly interact with each other. That is; PHP can not directly call a JavaScript function or access JavaScript values, and JavaScript can not directly call a PHP function or access PHP values.

However, because PHP is server-side, you can have PHP print JavaScript code, which will then be executed by the client when it reaches it.
Which also means that you can have PHP print values directly into JavaScript code, like Markus demonstrated.
Feb 16 '09 #5
6,050 Expert 4TB
I was hoping you'd explain.. I don't have the patience today.
Feb 16 '09 #6
thank you 4 ur replies... :)
Feb 17 '09 #7
6,050 Expert 4TB
Glad we could be of service!
Feb 17 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by David Shorthouse | last post: by
1 post views Thread by colleen1980 | last post: by
8 posts views Thread by BigZero | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.