Page 1 of 1

PASSING THE JAVASCRIPT VALUE TO PHP.. HELP!!!

Posted: Thu Oct 27, 2005 1:47 am
by tonton0731
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


help.. i need to pass the javascript value to php so that it will up date the field in the database... how will i do this?.. any code?.. i'm beginner so sori for my codes.
 my codes:

Code: Select all

<script type="text/javascript">
			function disp_prompt()
			{
			var $rate=prompt("Enter the Rate you desire.","")
			if ($rate!=null && $rate!="")
			{
				 
				 <?php 
				 											 		
						include ('../includes/config.php');
				 		$query="UPDATE rate SET perhour='+rate+' ";
                        $result = @mysql_query ($query);
				
						if($result = TRUE)
							{
								echo 'alert("Successfully change the Rate!! Press F5 refresh the system")';
							}
					else
							{
								echo 'alert("An Erro has Occured!!")';
							}
				 
				 ?>
				 	
			}
			}

feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Thu Oct 27, 2005 2:44 am
by feyd
It's not possible in the way you are trying to do it. PHP is a server-side only (as of right now anyways) language. Javascript is processed on the Client (browser) side most often. They do not mix in both directions. You can request that Javascript fill some values and do a form submission or go to a new url passing the data in that manor, but it will not be processed in the linear fashion you are assuming is possible.


In the future, please refrain from shouting through out the majority of your topic. Additionally, please read and understand the forums' many rules here..

Posted: Thu Oct 27, 2005 3:13 am
by tonton0731
putang ina ka!! ayaw pagbuot buot.. there another forum says that it's all right to pass javascript value to php..

Posted: Thu Oct 27, 2005 3:42 am
by Jenk
But as you are finding out, it's just not possible in the fashion you are attempting.

Sorry to point out the obvious.

Posted: Thu Oct 27, 2005 6:06 am
by Chris Corbyn
tonton0731 wrote:putang ina ka!! ayaw pagbuot buot.. there another forum says that it's all right to pass javascript value to php..
Whooaaa... another on for AJAX. AJAX can do this for you yes.

http://xajax.sourceforge.net/

It's not actually JS passing the value it's a new technology that allows sending a small packets of data to the server and receiving the result using try/catch.

Failing that, you can alsways have the page reload using

Code: Select all

window.location='this_location?varname='+js_var_here;
and have PHP read it from the URL via GET.

It's not straight forward to just do it in a linear fashion as feyd says.... in fact, it's not possible.

Posted: Thu Oct 27, 2005 7:37 am
by n00b Saibot
what say Chris, we declare today as AJAX day :D

Posted: Thu Oct 27, 2005 8:07 am
by Chris Corbyn
n00b Saibot wrote:what say Chris, we declare today as AJAX day :D
If we get many more posts that I can post the xajax link in then I might just have to do that! ;)