|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
php-javascript passing variables?!?!
I am developing a web application in php/javascript/dom... Recently I discovered the benefits of using dom with javascript... ie:being able to edit data without refreshing the browser, and seeing that my goal is to develop a fast application that works over an intranet it seemed that dom was the answer.
Now what I would like to do is start passing these javascript variables to php which is activated through javascript functions. Well my problem is basic, I have tried just about everything and I can’t seem to pass variables from javascript to php or from php to javascript?!?!?! Also when I have php attached in javascript functions it seems to run once and only once. Example: <HTML> <button onClick="php_script();">PHP_VAR_TEST</button> <script> var php_string =”0”; function php_script() { php_string =”<?$string1=string1+1;echo string1;?>”; alert(php_string); } </script> </HTML> Now, when I call the above script through a button command all I ever seem to get is the value 1. Every time I activate this command with the button. WHY? Which does the value of +1 only work once? Can anyone out there explain what I am doing wrong and how I can make this possible? Thanks in advance…. Chad |
|
#2
|
||||
|
||||
|
RE: php-javascript passing variables?!?!
Sorry, but I don't seem to understand. You want to run php commands from JavaScript? I don't think that's possible because php commands are handled by the server and JavaScript commands are handled by the browser. So if you want to do php commands, the page must be refreshed.
And the little piece of code. Put it this way: Code:
function php_script()
{
php_string =”<?$string1=$string1+1;echo string1;?>”;
alert(php_string);
}
What's different? If you give command $string1=string1+1, the $string1 will get the value from the variable string1. I suppose it should get its value from variable $string1 (from itself), right? |
|
#3
|
|||
|
|||
|
RE: php-javascript passing variables?!?!
Darn... that's not the answer I was hoping to receive. I can't refresh the entire page that will defeat my objective. My objective is to create a fast application that doesn't have to refresh.
I have discovered that DOM is very powerful and so far I am having great success. Uhmm there has got to be some way to accomplish what I want. Perhaps, I can find someway to post my javascript variables to a hidden php frame…and then have that data sent back to the javascript. That way it wouldn’t have to refresh the whole page…it would just refresh content on the page that was invisible. Either that…or I am going to have to learn to manipulate DOM through php… which will probably mean I would have to re-write my entire application… <evil grin>… Does this make any sense? LMAO You see the only real reason I need PHP is to call certain data from my mysql database and then update the database every time a customer finishes a transaction. Oh…in case anyone is wondering I am developing a web based cash register terminal for one of my customers. |
|
#4
|
||||
|
||||
|
RE: php-javascript passing variables?!?!
If it's only MySQL why you need php, why won't you code java applet instead of JavaScript? If I remember right it is possible to work with databases when using java applets. For more info on java applets and java, visit http://java.sun.com
|
|
#5
|
|||
|
|||
|
RE: php-javascript passing variables?!?!
Just a thought...
1. Fiddle with data using Javascript. 2. Write resulting JavaScript variable to hidden field in a form. 3. Read hidden field with PHP. 4. Process final page with PHP refresh. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > php-javascript passing variables?!?! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|