/    Sign up×
Community /Pin to ProfileBookmark

"null" in MSIE driving me crazy!

Hello I am new to this forum so I hope I can get some help. I thought I had successfully created a script that enabled a cookie displaying information to be displayed on a page. I used this:

if (phone == null) {
var phone_info = (”);
}
else {
var phone_info = (‘<center><font color=”red”><b>’ + phone + ‘</b></font></center>’);
}

document.write(” + phone_info + ”);

(phone is the information from the cookie, obviously a telephone number)

I had everything working great until I tested it on MSIE for Windows and if there’s no information from phone then MSIE displays null whereas in other browsers it just leaves it blank. No filler or anything. It’s probably something stupid but I’m no expert prgrammer and I need help. Thanks in advance.

Ammon

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@RibeyedJan 27.2003 — hi,

im no great javascript expert but i would change the code to this:

if (phone == "") {


so your saying if phone is equal to nothing then do.....

hope this helps
Copy linkTweet thisAlerts:
@ammonlovellauthorJan 27.2003 — I tried

if (phone == "") {

instead of

if (phone == null) {

but it hasn't made any difference. Thanks though. Maybe I should be more specific. I initially tried this:

if (referID == "") {

var refer_by_input = ('');

} else {

var refer_by_input = ('<center><table border="0" cellspacing="4" cellpadding="4"><tr><td VALIGN=middle><center><b><font face="Verdana, Helvetica, Arial" size="2">Welcome!<br>You are being referred to us by: <p></font></b><font color="red"><b>' + referID + '</b></font><input type="hidden" size="30" name="referred_by" value=' + referID + '><br><font color="red"><b>' + phone + '</b></font><br><font color="red"><b>' + email + '</b></font></center></td><td ALIGN=center VALIGN=middle>' + misc1 + '</td></tr></table></center><font color="red"><b>' + comments + '</b></font>');

}

document.write('' + refer_by_input + '');

But then I got those nulls and then I thought well maybe if I split it up and I did this:

if (referID == null) {

var refer_by_input = ('');

}

else {

var refer_by_input = ('<center><b><font face="Verdana, Helvetica, Arial" size="2">Welcome to Empower Net!<br>You are being referred to us by: </font></b><br></center><br>');

}

if (referID == null) {
var info_by_input = ('');
}
else {
var info_by_input = ('<center><font color="red"><b>' + referID + '</b></font><input type="hidden" size="30" name="referred_by" value=' + referID + '></center>');
}

if (misc1 == null) {
var misc1_by_input = ('');
}
else {
var misc1_by_input = ('<center>' + misc1 + '</center>');
}

if (phone == null) {
var phone_by_input = ('');
}
else {
var phone_by_input = ('<center><font color="red"><b>' + phone + '</b></font></center>');
}

if (email == null) {
var email_by_input = ('');
}
else {
var email_by_input = ('<center><font color="red"><b>' + email + '</b></font></center><br>');
}

if (phone == null) {
var comments_by_input = ('');
}
else {
var comments_by_input = ('<font color="red"><b>' + comments + '</b></font>');
}

document.write('' + refer_by_input + '');
document.write('' + misc1_by_input + '');
document.write('' + info_by_input + '');
document.write('' + phone_by_input + '');
document.write('' + email_by_input + '');
document.write('' + comments_by_input + '');


But it hasn't done me any good. It just does the exact same thing. Except that the second one gets rid of one null.
Copy linkTweet thisAlerts:
@RibeyedJan 27.2003 — hi,

can you post all the code for the page?

try writing the value of phone out to screen to make sure it is being pulled from the cookie.


You can may also, try a fix with adding in some code to stop the null being printed out.

try posting the code first, plz
Copy linkTweet thisAlerts:
@swonJan 27.2003 — Can you post a little bit more code, that we could see where does 'phone' come from!
Copy linkTweet thisAlerts:
@WebskaterJan 27.2003 — I think you need to decide if phone is null or an empty string or a string. So:

var phone_info = ""

if (phone == null) phone_info = '';

else if (phone == '') phone_info = '';

else phone_info = ('<center><font color="red"><b>' + phone + '</b></font></center>');

It seems a bit of overkill but is should solve your problem. IE, like all Microsoft programs is, quite rightly, very clear in the distinction between null and an empty string.
Copy linkTweet thisAlerts:
@ammonlovellauthorJan 27.2003 — Thanks for all your responses. I was not expecting so many so fast. I just tried what Webskater asked me to, and that didn't work either. Here's the long story. We are a small network marketing company and we receive sales through referrals. So my boss asked me to come up with a portal page where if someone visited the page of a distributor it would put that distributor's information on the online order form so that that distributor could get credit for referring that person. So I came up with a page that gives the information through a cookie and then it immediately redirects the personn to our home page and displays the informaion that was stored in the cookie. But the trick was getting it to display it without having it there permanent. So I fixed that but then I have this problem. In the next two posts I will post the page that the cookie is in and then the page that it displays. Thank you.
Copy linkTweet thisAlerts:
@ammonlovellauthorJan 27.2003 — <html>

<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<meta name="generator" content="Adobe GoLive 6">
<title>Empower Net</title>

<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

redirTime = "0";

redirURL = "http://www.empowernet.com/";

function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); }

// End -->

</script>

<script language="Javascript">

<!-- hide from old browsers

function GetCookie(name) {

var arg = name + "=";

var alen = arg.length;

var clen = document.cookie.length;

var i = 0;

while (i < clen) { var j = i + alen;

if (document.cookie.substring(i, j) == arg)

return getCookieVal (j);

i = document.cookie.indexOf(" ", i) + 1;

if (i == 0) break; } return null;

}

function setCookie(name, value, expires, path, domain, secure) {

document.cookie = name + "=" + escape(value) +

((expires == null) ? "" : "; expires=" + expires.toGMTString()) +

((path == null) ? "" : "; path=" + path) +

((domain == null) ? "" : "; domain=" + domain) +

((secure == null) ? "" : "; secure");

}

function delCookie (name,path,domain) {

if (getCookie(name)) {

document.cookie = name + "=" +

((path == null) ? "" : "; path=" + path) +

((domain == null) ? "" : "; domain=" + domain) +

"; expires=Thu, 01-Jan-70 00:00:01 GMT";

}

}

var expiration = new Date();

expiration.setTime(expiration.getTime() + (1 * 60 * 60 * 1000)); //1 hrs


//Distributor Name and ID go here

var referID = "John Doe - USA00000"

var phone = "Telephone: 480-555-9876"

var email = "E-mail: [email][email protected][/email]"

var comments = ""

var misc1 = ""

var misc2 = ""

var misc3 = ""


//set this cookie

setCookie('referID', referID, expiration, "/", 'www.empowernet.com');

setCookie('referID', referID, expiration, "/services/ordering/", 'www.empowernet.com');

setCookie('referID', referID, expiration, "/ordering/", 'www.empowernet.com');

setCookie('phone', phone, expiration, "/", 'www.empowernet.com');

setCookie('email', email, expiration, "/", 'www.empowernet.com');

setCookie('comments', comments, expiration, "/", 'www.empowernet.com');

setCookie('misc1', misc1, expiration, "/", 'www.empowernet.com');

setCookie('misc2', misc2, expiration, "/", 'www.empowernet.com');

setCookie('misc3', misc3, expiration, "/", 'www.empowernet.com');

// stop hiding -->

</script>

</head>

<body onLoad="redirTimer()" bgcolor="#ffffff">
<p></p>
</body>


</html>
Copy linkTweet thisAlerts:
@ammonlovellauthorJan 27.2003 — Here's the cookie-getter-part in the head:

<script language="Javascript">

<!-- hide

function getCookie(name) {

var arg = name + "=";

var alen = arg.length;

var clen = document.cookie.length;

var i = 0;

while (i < clen) { var j = i + alen;

if (document.cookie.substring(i, j) == arg)

return getCookieVal (j);

i = document.cookie.indexOf(" ", i) + 1;

if (i == 0) break; } return null;

}

function getCookieVal (offset) {

var endstr = document.cookie.indexOf (";", offset);

if (endstr == -1)

endstr = document.cookie.length;

return unescape(document.cookie.substring(offset, endstr));

}

function delCookie (name,path,domain) {

if (getCookie(name)) {

document.cookie = name + "=" +

((path == null) ? "" : "; path=" + path) +

((domain == null) ? "" : "; domain=" + domain) +

"; expires=Thu, 01-Jan-70 00:00:01 GMT";

}

}

var referID = getCookie("referID")

var phone = getCookie("phone")

var email = getCookie("email")

var comments = getCookie("comments")

var misc1 = parent.getCookie("misc1")

var misc2 = parent.getCookie("misc2")

var misc3 = parent.getCookie("misc3")

delCookie("referID", "/ordering", "www.empowernet.com");

function popUp(url)

{

sealWin=window.open(url,"win",'scrollbars=1,resizable=1,width=500,height=300');

self.name = "mainWin";

}

// stop hiding -->

</script>


The weird part is that if there is absolitely no info being passed, then everything is fine. If there's some info but not everything it doesn't work. Like for example if someone wanted to show their name and phone but not their email then in place of the email it would say null. If anyone wants to test it please go to http://www.empowernet.com/johndoe Here's the part that displays the info:



<td bgcolor="#FFFFFF" valign="top">

<script language="Javascript">

<!-- hide

if (referID == null) {
var refer_by_input = ('');
} else {
var refer_by_input = ('<center><table border="0" cellspacing="4" cellpadding="4"><tr><td VALIGN=middle><center><b><font face="Verdana, Helvetica, Arial" size="2">Welcome to Empower Net!<br>You are being referred to us by: <p></font></b><font color="red"><b>' + referID + '</b></font><input type="hidden" size="30" name="referred_by" value=' + referID + '><br><font color="red"><b>' + phone + '</b></font><br><font color="red"><b>' + email + '</b></font></center></td><td ALIGN=center VALIGN=middle>' + misc1 + '</td></tr></table></center><font color="red"><b>' + comments + '</b></font>');
}

document.write('' + refer_by_input + '');

// stop hiding -->

</script>

</td>
Copy linkTweet thisAlerts:
@ammonlovellauthorJan 28.2003 — Okay I posted my code and I would really appreciate some help on what I can do to make this work. Thanks.

Ammon
×

Success!

Help @ammonlovell spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...