Passing JS values to next page without editing body

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.
will4062Asked:
Who is Participating?
 
ZvonkoSystems architectCommented:
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
 
callrsCommented:
http://javascript.internet.com/forms/passing-values.html     The JavaScript Source: Forms: Passing Values
0
 
will4062Author Commented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
will4062Author Commented:
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
 
ZvonkoSystems architectCommented:
>> "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
 
will4062Author Commented:
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
 
will4062Author Commented:
That's working great! Thanks!

How would I get something like the state out of that cookie when it is listed differently?
0
 
ZvonkoSystems architectCommented:
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
 
will4062Author Commented:
What about for the state name?
It says this for state in the cookie:

State%75MI%20
0
 
ZvonkoSystems architectCommented:
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
 
ZvonkoSystems architectCommented:
Also a good tool to look for cookies and other page attributes is devic's PageSpy: http:/M_1344026.html
0
 
will4062Author Commented:
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
 
ZvonkoSystems architectCommented:
Can you guide me to the page where I can look for the cookie with PageSpy or where the cookie is generated?
0
 
will4062Author Commented:
Check the source here and search cookie:
http://motolures.com/store/index.html#32
0
 
ZvonkoSystems architectCommented:
Only three cookies there: s_cc, s_sq, ss_cart_0001228875
But no SSMBSuperCookie

0
 
will4062Author Commented:
Try adding the test item and checking out the cookies on the cart
0
 
ZvonkoSystems architectCommented:
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
 
will4062Author Commented:
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
 
ZvonkoSystems architectCommented:
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
 
will4062Author Commented:
That didn't work, tried both of those
0
 
ZvonkoSystems architectCommented:
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
 
will4062Author Commented:
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
 
ZvonkoSystems architectCommented:
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
 
will4062Author Commented:
Thanks!
0
 
ZvonkoSystems architectCommented:
You are welcome.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.