![]() |
passing a java variable to php
Hello dear colleagues from the TalkPHP forum,
I often use the "alert" java function in the middle of PHP programs in order to display variables on screen as shown below. PHP Code:
PHP Code:
Thanks in advance to all the help, pipesportugal |
1. What you are looking for should be coded in Javascript and not PHP, since the code runs on the client and not the server. For this just make the prompt-box calling a function which calls up the prompt-box again (when clicked on ok).
2. Anyhow, you could do it with PHP (and Javascript). Simply call the site again when clicking on ok - and just give a $_GET variable with. Then make php writing the confirm box again. So it would pop up untill the user klicks on cancel. But thats some dump and useless way to do it ;-) 3. Java != javascript |
That's not Java.
That's Javascript. Totally different. |
as said above, JavaScript ≠ Java in any way shape or form.
Anyway, the only way to pass any user information (JavaScript data is considered user data in this case, since all JavaScript is processed client side, or on the browser) to the server is through either a page reload with the content in a $_GET variable, or through an xmlHTTPrequest The first solution Code:
<script type="text/javascript" languge="JavaScript">The second solution is a little more in depth, but will look better. It will open a live connection with the processing page, send the information, and return the data... all without reloading your current page. This means it will be a real-time change to the user, making less click though and a (normally) more pleasurable visit to your site. Code:
<script type="text/javascript" charset="utf-8">This should get you started, there is a lot of documentation online about this stuff, and finding information on your own can help learn this stuff faster. Good Luck! |
Hi everyone,
Thank You to those that gave me their positive contribution. I acknowledge the fact that java is different from javascript, thank You all for that. Regarding Jason's suggestion, I dare at this point to ask him for a short "line by line" explanation of the example code that was posted here. Thanks in advance, pipesportugal |
Jason's suggestion if an example of AJAX
Code:
var request = false;Code:
if (!request) {This chunk does the work. Setting proper headers and sending the actual request. From the onreadystate property we can see that statusCheck has been set to verify results. Code:
function statusCheck(request) {This is statusCheck function which was set to check response and verify all went well if it did than use the returned data and if not alert the user. |
Aww man, I came in here to find javascript, not java. Would have been interesting to see what this could have been. :-(
|
HTML Code:
<script type="text/javascript" charset="utf-8"> |
You want to pass a JavaScript variable to PHP?
|
Hi everyone,
I will rephrase my question. I normally use the javascript function window.alert to stop the system and show me some variable values, this is a kind of my personal debugger. It stops, and then I look at the variabe value then click on OK and the program goes on... If I use the window.confirm will show me the OK and CANCEL buttons. After clcking the OK button the program will go on, and if I click the CANCEL button the program does the same. How can I find out on my php program, of which button has been clicked ? Thanks in advance for all the help, pipesportugal |
If you are looking to do what I think you want to do, you cant. Once the javascript is running, the php is already completed its job, and cannot be accessed again unless you use an AJAX call or refresh the page..
|
ok thank You so much Jason.
pipesportugal |
| All times are GMT. The time now is 10:13 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0