JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 8th, 2006, 12:47 PM
z2f10 z2f10 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 5 z2f10 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 11 sec
Reputation Power: 0
Passing variables to PHP using Javascript

I am having difficulty finding a way to pass variables to a PHP script using javascript. When I use the javascript

Code:
document.location.href="target.php?ID=2";


I get sent to the page target.php but with no ?ID=2. I am testing this on IE6. Any help would be appreciated.

Regards,

Rob

Reply With Quote
  #2  
Old September 8th, 2006, 11:12 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 542 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 2 h 56 m 21 sec
Reputation Power: 3
getting GET vars

The PHP file can use
PHP Code:
 $request_uri $_SERVER["REQUEST_URI"]; 
to get the URL. Then you can either use a regex or explode "?" - $arr[1], to get the portion you need (I don't think basename would work, but it might).

Reply With Quote
  #3  
Old September 12th, 2006, 11:14 AM
z2f10 z2f10 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 5 z2f10 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 11 sec
Reputation Power: 0
javascript assistance

Mittineague, thanks for the input. The problem I am having is getting javascript to put ANY values after the ?. Actually, if it would put a '?' I would feel like I am making headway. Here is a cut-n-paste example of the code I am trying to run.

Code:
<html>
<head>
<script type="text/javascript">

function UpdateVendor(SupplierID, PO, LineNo, DateRec, TimeRec)
{
	if(confirm("Are you sure you want to change the supplier?")){ 
	//display the data that should be included
alert ("SupplierID = " + SupplierID + "\nPO = " + PO + "\nLineNo = " + LineNo + "\nDateRec = " + DateRec + "\nTimeRec = " 

+ TimeRec);
	var mylink = "test2.html?SupplierID=" + SupplierID + "&PO=" + PO + "&LineNo=" + LineNo + "&DateRec=" + DateRec + 

"&TimeRec=" + TimeRec;
	location.href = mylink;
	
	//location.href = location.href + "?" + "SupplierID=" + SupplierID + "&PO=" + PO + "&LineNo=" + LineNo + "&DateRec=" + 

DateRec + "&TimeRec=" + TimeRec;
	}
}

</script>

</head>
<body>
<table>
	<tr>
		<td>PO</td>
		<td>Line No</td>
		<td>Date Rec</td>
		<td>Time Rec</td>
		<td>Vendor</td>
	</tr>
	<tr><form name=myform>
		<td><input name = "PO" type="text" value="12345"></td>
		<td><input name = "LineNo" type="text" value="1"></td>
		<td><input name = "DateRec" type="text" value="08/11/2006"></td>
		<td><input name = "TimeRec" type="text" value="12:45 PM"></td>
		<td>
		<select Name = "SupplierID" ONCHANGE="UpdateVendor(myform.SupplierID.options[selectedIndex].value, 

myform.PO.value, myform.LineNo.value, myform.DateRec.value, myform.TimeRec.value)">
			<option value="1">Company 1</option>
			<option value="2">Company 2</option>
			<option value="3">Company 3</option>
			<option value="4">Company 4</option>
		</select>
		</td></form>
	</tr>
	<tr><form name=myform2>
		<td><input name = "PO" type="text" value="22222"></td>
		<td><input name = "LineNo" type="text" value="21"></td>
		<td><input name = "DateRec" type="text" value="08/21/2006"></td>
		<td><input name = "TimeRec" type="text" value="2:30 PM"></td>
		<td>
		<select Name = "SupplierID" ONCHANGE="UpdateVendor(myform2.SupplierID.options[selectedIndex].value, 

myform2.PO.value, myform2.LineNo.value, myform2.DateRec.value, myform2.TimeRec.value)">
			<option value="1">Company 1</option>
			<option value="2">Company 2</option>
			<option value="3">Company 3</option>
			<option value="4">Company 4</option>
		</select>
		</td></form>
	</tr>	

</body>
</html>


So, my initial problem is as it stands, I am having difficulty finding a way to pass variables to a PHP script using javascript.

Reply With Quote
  #4  
Old September 12th, 2006, 02:17 PM
z2f10 z2f10 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2006
Posts: 5 z2f10 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 11 sec
Reputation Power: 0
Thumbs up Solved

The problem was that I was passing only one file and not the entire path.

Code:
document.location.href="target.php?ID=2";


Did not work but

Code:
document.location.href="http://127.0.0.1/target.php?ID=2";


Does.

Last edited by z2f10 : September 15th, 2006 at 10:43 AM. Reason: remove domain name

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Passing variables to PHP using Javascript


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway