473,398 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

undefined error on first execution of function

On first execution of StartSurf() the siteloc returns undefined

On second excution and after that there is no problem.

StartSurf is called from a button press, which becomes invisible for 30
seconds and then visible again.

Suggest solution.

The code I am using is
=========================
var siteloc;
var siteid;
var nVar;
var sitesurfed;
function StartSurf()
{
document.getElementById('surf21').style.visibility ='hidden';
nVar = 30;
callSite()

if (siteloc = "")
{
exitSurf()
}
else
{
callTimer()
}
}

function callTimer()
{
if (nVar >= 0)
{
T1.innerHTML = "<b><font color='#FFFFFF'>" + nVar + "</font></b>";
nVar = nVar - 1;
Timer()
}
else
{
document.getElementById('surf21').style.visibility ='visible';
}
}

function Timer()
{
window.setTimeout("callTimer()", 1000);
}

function callSite()
{
var file = 'surfdb.asp?T=' + Date();
getSurf(file)

var msg1 = "<b><font color='#FFFFFF'><a style='color: #FFFFFF;
font-size: 10pt; font-weight: ";
msg1 = msg1 + "bold' target='_blank' href='" + siteloc + "'>Open
Site</a></font></b>";
T2.innerHTML = msg1;

var msg5 = "<b><font color='#FFFFFF'>Surfed: " + sitesurfed +
"</font></b>";
T5.innerHTML = msg5;

var msg2 = "<b><font color='#FFFFFF'><a style='color: #FFFFFF;
font-size: 10pt; font-weight: ";
msg2 = msg2 + "bold' target='_blank' href='reportabuse.asp?siteid=" +
siteid + "'>Report Abuse</a></font></b>";
T3.innerHTML = msg2;

document.getElementById('surfFrame').src = siteloc;
}

function getSurf(file)
{
var scriptTag = document.getElementById('loadScript');
var head = document.getElementsByTagName('head').item(0)
if(scriptTag) head.removeChild(scriptTag);
script = document.createElement('script');
script.src = file;
script.type = 'text/javascript';
script.id = 'loadScript';
head.appendChild(script)
}

function exitSurf()
{
document.getElementById('surf21').style.visibility ='hidden';
document.getElementById('surfFrame').src = "surfcomp.asp?x=" +
Date();
T1.innerHTML = "";
T0.innerHTML = "";

var msg3 = "<b><font color='#FFFFFF'><a style='color: #FFFFFF;
font-size: 10pt; font-weight: ";
msg3 = msg3 + "bold' href='members.asp?x=" + Date() + "'>My
Account</a></font></b>";
T2.innerHTML = msg3;

T3.innerHTML = "";
}
====================

--------------------------
My websites
http://www.eecpworld.com/
http://www.indiapropertyhome.com/
http://www.wahmdirect.com/
http://www.indianmatrimonialnet.com/

*** Sent via Developersdex http://www.developersdex.com ***
Aug 20 '06 #1
1 1535
preet said the following on 8/20/2006 2:26 PM:
On first execution of StartSurf() the siteloc returns undefined
That's because it is undefined. It is initialized but it is still undefined.
On second excution and after that there is no problem.
Because afterwards it is defined.
StartSurf is called from a button press, which becomes invisible for 30
seconds and then visible again.
Suggest solution.
First suggestion: Do some reading, starting with this groups FAQ and the
Best Practices document, both are in my signature.

Second suggestion: Stop using IE only shortcut coding.

Third suggestion: Stop coding in HTML3.2
Fourth suggestion: Properly delimit your signature.
Fifth suggestion: Find a better Usenet provider than devex
Sixth suggestion: Post a URL to your modified code that doesn't use
HTML3.2, doesn't use IE only shortcut coding (I refer to it as lazy-coding).

Need more suggestions?

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: shablool | last post by:
Hi all, Two distinct compilers give different output for the following code: #include <iostream> #include <string> int main(void) { std::string s("0124"); s.replace(0, 3,...
25
by: Nitin Bhardwaj | last post by:
Well, i'm a relatively new into C( strictly speaking : well i'm a student and have been doing & studying C programming for the last 4 years).....and also a regular reader of "comp.lang.c" I...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
17
by: yb | last post by:
Hi, Looking for clarification of undefined variables vs. error in JavaScript code. e.g. <script> alert( z ); // this will be an error, i.e. an exception </script>
28
by: robert | last post by:
In very rare cases a program crashes (hard to reproduce) : * several threads work on an object tree with dict's etc. in it. Items are added, deleted, iteration over .keys() ... ). The threads are...
1
by: Noggon | last post by:
Maybe I'm stupid, but I can't find out what is wrong, can anyone help? I keep getting the function first as being undefined for some reason I don't get. I'm trying to use setTimeout() to pause...
45
by: VK | last post by:
(see the post by ASM in the original thread; can be seen at <http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/3716384d8bfa1b0b> as an option) As that is not in relevance to...
3
by: Anonymous Infidel - Aborted Islam with a hanger | last post by:
I have two classes(class A, class main). class main uses a pointer to class A and class A uses a global pointer to main. My problem is I keep getting these errors: :( a.h(12) : error C2027: use...
33
by: coolguyaroundyou | last post by:
Will the following statement invoke undefined behavior : a^=b,b^=a,a^=b ; given that a and b are of int-type ?? Be cautious, I have not written a^=b^=a^=b ; which, of course, is undefined....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.