472,331 Members | 1,690 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,331 software developers and data experts.

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 12853
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

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

Similar topics

by: Matt | last post by:
My problem is to allow ASP to interact with JSP, and I pass JavaScript object in my approach, but I wonder if it will work in network, not just in...
by: Seeker | last post by:
Newbie question here... I have a form with some radio buttons. To verify that at least one of the buttons was chosen I use the following code...
by: David Shorthouse | last post by:
Folks, I have a drop-down select menu generated server-side. I was hoping to pass more than a single variable from the option value to a...
by: praveenit | last post by:
hi, I am writing a small java script code where , when the textbox is clicked a pop up window is opened . on entering some data in the text area...
by: colleen1980 | last post by:
Hi: Can any one please tell me that how to i pass the two textbox values in the new page. If i use the form action in the popup window page then...
by: Steve Kershaw | last post by:
Hi, I need to pass a value from a hidden input: <input id="hiddentxtWidth" type="hidden" value="1065" /> to a JavaScript function. I've tried...
by: msg2ajay | last post by:
hello , i have to pass a 'span' id to the javascript function'. how can i pass that. when i tried like below it is working!!! may...
by: IRC | last post by:
hey, i am pretty new on javascript as well as PHP, Hey, anyone can you help me, how to pass the javascript array value to php page......... i...
by: JohnDriver | last post by:
Hi, I am having a form which has a text box and 3 radio buttons. I am using GET method in Ajax to pass the value. I can pass the value of the...
by: BigZero | last post by:
Hello, i need to pass some variables or value to javascript from php script. well all i need to pass to value to javascript that is with in same...
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.