Click to See Complete Forum and Search --> : [RESOLVED] Need help with javascript.


Angel_icy
07-31-2008, 06:13 AM
Hey all

I need help from javascript expert to see where did i go wrong in my codes. Reason being when i open it now it not working compare to when i open it last time. So i need help in debugging my codes. As for the external javascript i believe it is working cause i tested it in a blank html file. But when i integrate into this webpage which i building for educational purpose it like not responding to the event. So if any expert is around tonight please reply soon. Needed to submit by tomorrow.


======
codes in html files
======
<script type="text/javascript" src="wz_tooltip.js">
<!--
function popup(url)
{
var width=500;
var height=350;
var left=(screen.width-width)/2;
var top=(screen.width-width)/2;
var params='width='+width+',height='+height;
params +=', top='+top+', left='+left;
params +=', directories=no';
params +=', location=no';
params +=', meunbar=no';
params +=', resizeable=no';
params +=', scrollbars=no';
params +=', status=no';
params +=', toolbar=no';
newwin=window.open(url,'windownames', params);
if(window.focus) {newwin.focus()}
return false;
}

//-->
</script>

<!--Begin of table-->
<table border="0" align="center">
<tr><th align="center"><h2>History of Singapore</h2></th></tr>
<tr><td align="center">Mouse over to see title and click on the dots to learn the history</td></tr>
<tr><td>
<!--Begin of imagemap-->
<img src="Singapore_map_w.jpg" alt="" usemap="singapore" border="0" align="center">
<map name="singapore">
<area name="1600" shape="circle" coords="269,447,6" href="javascript:void(0)"
onmouseover="Tip('Influence of India and Thailand')"
onmouseout="UnTip()" >

<area name="1800" shape="circle" coords="200,401,6" href="javascript:void(0)"
onmouseover="Tip('Jostling of power between the Dutch and British')"
onmouseout="UnTip()" onclick="popup('popup/1800.html')">

<area name="1819" shape="circle" coords="56,404,6" href="javascript:void(0)"
onmouseover="Tip('Modern Singapore and Sir Stamford Raffles claimed')"
onmouseout="Untip()" onclick="popup('popup/1819.html')">

<area name="1875" shape="circle" coords="86,316,6" href="javascript:void(0)"
onmouseover="Tip('Singapore population grew in number')"
onmouseout="Untip()" onclick="popup('popup/1875.html')">

<area name="1900" shape="circle" coords="150,263,6" href="javascript:void(0)"
onmouseover="Tip('Singapore the Straits Settlement')"
onmouseout="Untip()" onclick="popup('popup/1900.html')">

<area name="1910" shape="circle" coords="163,333,6" href="javascript:void(0)"
onmouseover="Tip('Three Major Ethnicities vs British')"
onmouseout="Untip()" onclick="popup('popup/1910.html')">

<area name="1920" shape="circle" coords="276,254,6" href="javascript:void(0)"
onmouseover="Tip('Origins of Singlish')"
onmouseout="Untip()" onclick="popup('popup/1920.html')">

<area name="1950" shape="circle" coords="478,361,6" href="javascript:void(0)"
onmouseover="Tip('Popularity of English on the rise')"
onmouseout="Untip()" onclick="popup('popup/1950.html')">

<area name="1960" shape="circle" coords="385,431,6" href="javascript:void(0)"
onmouseover="Tip('Studies of Singlish')"
onmouseout="Untip()" onclick="popup('popup/1960.html')">

<area name="1965" shape="circle" coords="360,360,6" href="javascript:void(0)"
onmouseover="Tip('Popularity of English on the rise - part 2')"
onmouseout="Untip()" onclick="popup('popup/1965.html')">

<area name="1975" shape="circle" coords="274,378,6" href="javascript:void(0)"
onmouseover="Tip('The main language in Singapore')"
onmouseout="Untip()" onclick="popup('popup/1965.html')">

<area name="1980" shape="circle" coords="270,328,6" href="javascript:void(0)"
onmouseover="Tip('The badge for most Singaporean')"
onmouseout="Untip()" onclick="popup('popup/1980.html')">

Kostas Zotos
07-31-2008, 09:47 AM
Hi,

The embeded code (the "popup" function) will be executed only when the external JS file failed to load.. Since the "wz_tooltip.js" loaded normally the embeded script just ignored..

(You have set the "popup" function as the alternative script inside your external script declaration, which means that embeded scipt "popup" function will be used only in case the external source AS failed to load)

Try this (note in red color the addition):

<script type="text/javascript" src="wz_tooltip.js"></script>

<script language="javascript">
<!--
function popup(url)
{
var width=500;
var height=350;
var left=(screen.width-width)/2;
var top=(screen.width-width)/2;
var params='width='+width+',height='+height;
params +=', top='+top+', left='+left;
params +=', directories=no';
params +=', location=no';
params +=', meunbar=no';
params +=', resizeable=no';
params +=', scrollbars=no';
params +=', status=no';
params +=', toolbar=no';
newwin=window.open(url,'windownames', params);
if(window.focus) {newwin.focus()}
return false;
}

//-->
</script>

Now the above are two different scripts (independnt of each other)..

Regards!

Kostas

Angel_icy
07-31-2008, 09:53 PM
Thanks Kostas,

Anyway i manage to find a better javascript and got it running.

-------------------------Tooltips javascript codes-----------------------
if (!document.layers&&!document.all&&!document.getElementById)
event="test"
function showtip(current,e,text){

if (document.all||document.getElementById){
thetitle=text.split('<br>')
if (thetitle.length>1){
thetitles=''
for (i=0;i<thetitle.length;i++)
thetitles+=thetitle[i]
current.title=thetitles
}
else
current.title=text
}

else if (document.layers){
document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
document.tooltip.document.close()
document.tooltip.left=e.pageX+5
document.tooltip.top=e.pageY+5
document.tooltip.visibility="show"
}
}
function hidetip(){
if (document.layers)
document.tooltip.visibility="hidden"
}

</script>
<div id="tooltip" style="position:absolute;visibility:hidden"></div>
---------------------------------------------------------------------

So my image map code is now like this shown below:

----------------------------------------------------------------------
<area name="1600" shape="circle" coords="269,447,6" href="javascript:void(0)"
onMouseover="showtip(this,event,'Influence of India and Thailand')"
onMouseout="hidetip()" onclick="popup('popup/1600.html')">

-----------------------------------------------------------------------
Updated code are in red. Btw, it's a tooltips for image map.

The main source is from here :http://www.dynamicdrive.com/dynamicindex5/texttool.htm