Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alert box "undefined"

Status
Not open for further replies.

wolfmah

Programmer
Oct 24, 2001
17
CA
Hi there!
I was typing some lines of code to tell the visitor of my site what is the resolution of his screen, so he could change it or not to the one I'm using for my web site. Here the sample :

<script language=&quot;JavaScript&quot;>
<!--
var width=screen.availWidth;
var height=screen.availHeight;

function condition()
{
if (width >= 1024 && height >= 768)
{
alert('Width : ' + width + '\n'
+ 'Height : ' + height);
}
else
{
alert('Width : ' + width + '\n'
+ 'Height : ' + height + '\n'
+ '\nYou´d better change your'
+ '\nresolution to 1024 x 768'
+ '\n\nThat way, your experience on'
+ '\nthis web site will be better.');
}
}
//-->
</script>
<a href=&quot;&quot; onClick=&quot;alert(condition())&quot;>Want to see your resolution?</a>

My question is why am I always getting a second alert box with the string &quot;undefined&quot; in it? I tried to get rid of it but I failed. Help on this one will not be refused.

wolfmah
wolfmah@wolfmahheaven.net
 
The problem is in your <a> tag. First off, your href is set to nothing, therefore, even if you did get the function to work, your browser would try to navigate to... well, nothing :)..

By setting the href property to your function, only the function will be called when the link is clicked. OK, that resolves the navigation problem. The alert / undefined problem was because you were calling the function inside of an alert method. Just call the function only. You've got the alert methods already written into your function.

The line below should do the trick..

Code:
<a href=&quot;javascript:condition();&quot;>Want to see your resolution?</a>

ToddWW :)
 
DUH! I still need a few things to learn. Thank, it work perfectly now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top