473,569 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to pass php value to javascript function?

16 New Member
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 12961
6,050 Recognized Expert Expert
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
sweetline priya
16 New Member
can u explain how to call this function ?? within php coding?? or in onSubmit, onclick events??
Feb 16 '09 #3
6,050 Recognized Expert Expert
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="doFunction('<?php echo $var; ?>');">Click</a>
Feb 16 '09 #4
5,058 Recognized Expert Expert
@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 Recognized Expert Expert
I was hoping you'd explain.. I don't have the patience today.
Feb 16 '09 #6
sweetline priya
16 New Member
thank you 4 ur replies... :)
Feb 17 '09 #7
6,050 Recognized Expert Expert
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 local machine. For testing purposes, the following are page1.html and page2.html that use Array JavaScript object to pass data back and forth. page1.html is able to transfer data to page2.html,...
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 ("f" is my form object) : var btnChosen; for (count = 0; count <= 1; count++) { if (eval(f.RadioButtons.checked)) { btnChosen = true; }
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 javascript function. Is this possible? At the moment, my option values consist of three numbers separated by commas. I thought I could pass these three numbers as three distinct variables to the javascript...
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 present in pop up window and pressing ''save" button the pop up is closed and the value is put in the text box of parent window. Now the value is getting passed from pop up to parent but from parent to...
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 the new page is open in the same popup window as i need to open the new page in the main page window with passing the two textbox parameters into the new page. Program opens the new page but dont know...
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 the following: <script type="text/javascript" > window.resizeTo(<%= hiddentxtWidth.value %>, <%= hiddentxtHeight.value %>);
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 the function is in the same page.... eg: ---- <html> function dscptAction(){ var obj = document.getElementsByTagName("span");
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 want to retrieve the values which are arrayed on "selectedValues" from next page for php variable this is my javascript code saved on "sendValue.js" file, <script> function...
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 textbox fine but how to pass the value of radio button? I searched a few things on Google but I find the javascript below most useful in my case but there is some problem that my code is not running: ...
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 php file the two values r in php i need to pass it to javascript from there to ext page the following code make clear <?php
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.