Solved

Passing JS values to next page without editing body

Posted on 2006-06-30
25
328 Views
Last Modified: 2006-11-18
I have a bit of an issue. I am currently using a system called ShopSite to manage my shopping cart. For all javascript and HTML additions you want to do, you have to do them in special areas on the control panel, therefore only letting you add snippits of code by themselves to the header and above or below certain areas on the page.

In the main checkout page, for example, this is displayed in the source code:

<input type=text name=zip_code value="48168" size=10 maxlength=20>

The value of the zip code field is entered by the user on that page, and I want to grab that dynamic value for the zip and carry it over the the next page (the thank you page).

However, no matter what I do, the zip code won't read when I do a document.write on the next page, using the name "zip_code" to call it.

I have also tried to add this to one of the custom HTML areas on the checkout page:

<SCRIPT>
function zipper()
{
var splitChar = "~";
var locs = "thankyou.cgi?";
locs+= [[[zip_code]]].value + splitChar;
location.replace(locs);
}
</SCRIPT>

and this to the thank you page:

<SCRIPT LANGUAGE="JavaScript">
var splitChar = "~";
//Puts the vars in an array
var values =  location.search.substring(1).split(splitChar);
alert("zip_code 1 = " + values[0]);
alert(values);

</SCRIPT>

What is an ideal way to go about doing this? All I want to do is transfer the value of the zip code from the checkout page so an analytic script can read it from the thank you page.
0
Comment
Question by:will4062
  • 12
  • 12
25 Comments
 
LVL 30

Expert Comment

by:callrs
Comment Utility
http://javascript.internet.com/forms/passing-values.html     The JavaScript Source: Forms: Passing Values
0
 

Author Comment

by:will4062
Comment Utility
My situation is different, I've spent 10+ hours on this already (all because of the shitty shop system)

Also, all of the shop values are stored in 1 cookie, so I dont know how I would retrieve just the zip code value from the cookie
0
 

Author Comment

by:will4062
Comment Utility
Also, I just tried that zip and it looks like it adds the values to the URL, which messes up the values that the shop uses to get to the next page (ie. store id), therefore making it unfunctional
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
>> "all of the shop values are stored in 1 cookie..."
Put this on your page and copy the cookie value here for analyzis:
<script>prompt('',document.cookie)</script>

Also it would be interesting to see the complete html source of the page where the zipper() function is embedded.


0
 

Author Comment

by:will4062
Comment Utility
Here is the data from the cookie that was prompted:

sbid=SSMSB1151525029.40855; SSMBSuperCookie=%20Company%75%20Email%75awdasdfasd@sad.com%20Address%75asdasd%20Address2%75%20City%75asd%20State%75ID%20Zip%7548168%20Country%75United_States%20Phone%752222222222%20ShipCompany%75%20ShipAddress%75%20ShipAddress2%75%20ShipCity%75%20ShipState%75%20ShipZip%75%20ShipCountry%75%20ShipPhone%75%20Title%75asd%20First%75assd%20Middle%75asd%20Last%75asd%20Suffix%75%20ShipTitle%75%20ShipFirst%75%20ShipMiddle%75%20ShipLast%75%20ShipSuffix%75; ss_return_info=tax:3|zip:48168|country:US|cc:0|; s_cc=true; s_sq=%5B%5BB%5D%5D; _c=y; ss_cart_0001228875=|LineCnt:1|QntyTotal:1|SubTotal:$0.00|1:$0.00:Unavailable|

How can I get the zip:48168 from that?

Also, here are the pages we are working on so you can check out the source code:

http://motolures.com/cgi-bin/sc/order.cgi?rd=1&storeid=*1267f1a681d50b66ae10c2&sbid=SSMSB1151525029.40855&prevlocation=http://motolures.com/store/index.html
https://motolures.com/cgi-bin/sc/billing.cgi?storeid=*1267f1a681d50b66ae10c2&fromid=order.cgi&redirect=yes&shopinfo=SSMSB1151525029.40855
https://motolures.com/cgi-bin/sc/thankyou.cgi
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 500 total points
Comment Utility
Getting the zip from your document.cookie is as easy as this:

<script>
var zip = document.cookie.split("|zip:");
if(zip.length>1){
  zip = zip[1].split("|")[0];
}else{
  zip="";
}
</script>

0
 

Author Comment

by:will4062
Comment Utility
That's working great! Thanks!

How would I get something like the state out of that cookie when it is listed differently?
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
You mean if it is not: |country:US|

As easy as this:
<script>
if(document.cookie.indexOf("|country:US|")<0){
  alert("Not in the Sates!");
}
</script>

0
 

Author Comment

by:will4062
Comment Utility
What about for the state name?
It says this for state in the cookie:

State%75MI%20
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
That SSMBSuperCookie does not appier on your pages anymore.
Also it does not make much sense to me. The separator char in the cookie is %75, but that is ASCII char "u"
Do you see any cookie of that type enymore?

0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Also a good tool to look for cookies and other page attributes is devic's PageSpy: http:/M_1344026.html
0
 

Author Comment

by:will4062
Comment Utility
Yes, I just had to take off the prompt because customers were questioning it.

The cookie is still there, but I need to read the state data too for my reports.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Can you guide me to the page where I can look for the cookie with PageSpy or where the cookie is generated?
0
 

Author Comment

by:will4062
Comment Utility
Check the source here and search cookie:
http://motolures.com/store/index.html#32
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Only three cookies there: s_cc, s_sq, ss_cart_0001228875
But no SSMBSuperCookie

0
 

Author Comment

by:will4062
Comment Utility
Try adding the test item and checking out the cookies on the cart
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Anyway, doing that cookie stuff on browser side does not make much sense.
You have to read and write the Cookie values in the /thankyou.cgi
Do you do that CGI coding for /thankyou.cgi in Perl?

0
 

Author Comment

by:will4062
Comment Utility
I have no idea how the system was made, it's a shopping cart system and it doesnt let you edit individual files

All I need is to have the state value in the cookie read in thankyou.cgi
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
OK, you can read it like this:
<script>
var uState = document.cookie.split(" State%75");
if(uState.length>1){
  uState = uState[1].split(" ")[0];
}else{
  uState="";
}
</script>

The same is also when you need ShipState:
<script>
var sState = document.cookie.split(" ShipState%75");
if(sState.length>1){
  sState = sState[1].split(" ")[0];
}else{
  sState="";
}
</script>



0
 

Author Comment

by:will4062
Comment Utility
That didn't work, tried both of those
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
So your cookie value extractor could be something like this:

<script>
function getCookieVal(cName, cSuff){
  if(cSuff=="|"){
    cName = "|"+cName+":";
  } else {
    cName = " "+cName+"%75";
    cSuff = " ";
  }
  var cVal = document.cookie.split(cName);
  if(cVal.length>1){
    return (cVal[1]+cSuff).split(cSuff)[0];
}

// get the values like this:

var zip = getCookieVal("zip","|");
var uState = getCookieVal("State");
var sState = getCookieVal("ShipState");

</script>


0
 

Author Comment

by:will4062
Comment Utility
I got it without doing that, I just changed the splitter:

<script>
var sState = document.cookie.split("%20State%75");
if(sState.length>1){
  sState = sState[1].split("%20")[0];
}else{
  sState="";
}
document.write(sState);
</script>

Thanks for your help!
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
Uhps, right, they encode the blank with %20!
Ok, the upper script then has to be like this:

<script>
function getCookieVal(cName, cSuff){
  if(cSuff=="|"){
    cName = "|"+cName+":";
  } else {
    cName = "%20"+cName+"%75";
    cSuff = "%20";
  }
  var cVal = document.cookie.split(cName);
  if(cVal.length>1){
    return (cVal[1]+cSuff).split(cSuff)[0];
}

// get the values like this:

var zip = getCookieVal("zip","|");
var uState = getCookieVal("State");
var sState = getCookieVal("ShipState");

</script>


0
 

Author Comment

by:will4062
Comment Utility
Thanks!
0
 
LVL 63

Expert Comment

by:Zvonko
Comment Utility
You are welcome.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now