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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tonton0731
Forum Newbie
Posts: 2
Joined: Thu Oct 27, 2005 1:42 am
Contact:

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

Post 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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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..
tonton0731
Forum Newbie
Posts: 2
Joined: Thu Oct 27, 2005 1:42 am
Contact:

Post by tonton0731 »

putang ina ka!! ayaw pagbuot buot.. there another forum says that it's all right to pass javascript value to php..
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

what say Chris, we declare today as AJAX day :D
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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! ;)
Post Reply