Click to See Complete Forum and Search --> : cookie parse out,,,
erick
06-02-2003, 11:18 PM
Hello all,
I have a cookie set with 4 values i.e.
cookie = value1::value2::value3::value4
trying to strip the values but can not get to the 3rd and fourth value... here is what I'm trying....
var setlinknames=getCookie('Setlinknames');
var setlinkname1;
var setlinkname2;
var setlinkname3;
var setlinkname4;
if(setlinknames.indexOf('::')==-1){
setlinkname1=setlinknames;
setlinkname2="";
setlinkname3=" ";
setlinkname4=" ";
}
else{
setlinkname1=setlinknames.substring(0,setlinknames.indexOf("::"));
setlinkname2=setlinknames.substring(setlinknames.indexOf("::")+2, setlinknames.length);
<!-- works to this point the 2nd value is returned for 3 and 4-->
if(setlinknames.indexOf('::')==-1){
setlinkname3="";
setlinkname3=setlinknames.substring(setlinknames.indexOf("::")+4, setlinknames.length);
if(setlinknames.indexOf('::')==-1){
setlinkname4="";
setlinkname4=setlinknames.substring(setlinknames.indexOf("::")+6, setlinknames.length);
}
out put...
Value1 Value2:::: Value2:::: Value2::::
Please what am I missing ??
Thx
Erick
Gollum
06-03-2003, 01:56 AM
This looks like a job for regular expressions - a much feared and misunderstood tool available in Javascript...
For example if your string looks like this...
var str = "value:1::value 2::value3::value4";
then
str.split(/::/);
returns an array of four strings:
["value:1","value 2","value3","value4"]
Note: I added the single ':' to show that split(/::/) splits only on double : boundaries.
erick
06-03-2003, 02:03 AM
All right !!!
var setlinkurlcrumbs = setlinkurls.split("::");
var setlinkurl1 = setlinkurlcrumbs[0];
var setlinkurl2 = setlinkurlcrumbs[1];
var setlinkurl3 = setlinkurlcrumbs[2];
var setlinkurl4 = setlinkurlcrumbs[3];
Works exellent...
now trying to get a hrefs to work...
using.. want is to TARGET
the setlink url is set now as
http://www.global411.net target=”content
setting the <a href=" as hard code so the cookie filles the center of the href...
then hard coding the "> in the linkurl script to finish the href..
won't link or the " for the target comes up as a black block not a " so I'm guessing it is not reconizing it..
<td>
<a href="<script language="JavaScript" type="text/javascript">
document.write(' '+setlinkurl1+' ">');
document.write(' '+setlinkname1+'</a> ');</script>">
</td>
Thx..
Erick
Gollum
06-03-2003, 02:19 AM
<a href="<script language="JavaScript" type="text/javascript">document.write(' '+setlinkurl1+' ">');document.write(' '+setlinkname1+'</a> ');</script>">
Hmmm. Might be a fine model in ASP, but HTML and Javascript don't work like that.
sounds like what you want is more like this...
<a href="javascript:void 0;" id="myLink">Watch this space!</a>
then when the HTML has loaded (use onload event on the <body> tag)
var oA = document.getElementById('myLink');
oA.href = setlinkurl1;
if ( oA.text ) oA.text = setlinkname1;
else oA.innerHTML = setlinkname1;
erick
06-03-2003, 02:31 AM
I'm sorry I do not understand ...:confused:
Gollum
06-03-2003, 02:48 AM
OK, the problem with saying...
<a
href="<script language="JavaScript" type="text/javascript">
document.write(' '+setlinkurl1+' ">');
document.write(' '+setlinkname1+'</a> ');
</script>"
>
is that it's not good HTML, and browsers will get confused - particularly with all the quotes.
What you need to do is set up your link (the <a> tag) with dummy values and some unique ID and then once the HTML page has loaded, fill in the values afterwards.
e.g.
<html>
<head>
<script language="Javascript">
var setlinkurlcrumbs = setlinkurls.split("::");
var setlinkurl1 = setlinkurlcrumbs[0];
var setlinkurl2 = setlinkurlcrumbs[1];
var setlinkurl3 = setlinkurlcrumbs[2];
var setlinkurl4 = setlinkurlcrumbs[3];
function Setup()
{
// get a reference to the link object below.
var oA = document.getElementById('myLink');
// set the href on the link
oA.href = setlinkurl1;
// set the text of the link
if ( oA.text ) oA.text = setlinkname1; // netscape 4 & up
else oA.innerHTML = setlinkname1; // most other browsers
}
</script>
</head>
<body onload="Setup();">
<a href="" id="myLink">Watch this space!</a>
</body>
</html>
erick
06-03-2003, 02:59 AM
Ok..
before I set all this up "THANK YOU"
this seems really close..
document.write('<A HREF="javascript:void.content.frames.location.href='+setlinkurl1+' "> ');
just getting line: 1 char: 5 Error: syntax error
???
Thx
Erick..
Gollum
06-03-2003, 03:33 AM
It's probably the '.' after void in the statement "javascript:void.content.frames..."
If you're happy writing the link out in full, how about...
document.write('<a href="' + setlinkurl1 + '">' + setlinkname1 + '</a>');
erick
06-03-2003, 11:12 AM
This would be fine... I can get it to link but it is targeting the content frame that I can not get...
erick
06-03-2003, 11:17 AM
got it.... was simple when I looked at it again this morn, :rolleyes:
document.write('<a href=" '+setlinkurl2+' " target="content">');
ok now in the scripting ig the value is "null" notthing defined how do I get it to display notthing ?? no null or undefined or anything unless there is somthing to display ??/
Thx,
Erick