PDA

View Full Version : Need help with a script modification...



JVRudnick
Sep 14th, 2004, 11:19 PM
Hello all..
I am using a short script that will enable me to put a set of buttons on an html page, that when clicked by a user will simply hide/show text links beneath.

So far, I have been able to 'modify' the code to allow me to use a simple <a href="newpage.html"> text here </a> no problems at all.

Its the few links that I wish to use to popup a javascript window that is causing me grief....can someone tell me how to work this? The " or the ' are not working....



<html>
<head>
<script language=Javascript type="text/Javascript">

function newWindow2(fishStory) {

fishWindow = window.open(fishStory, 'fishWin', 'toolbar=no, location=no, scrollbars=yes, width=400, height=500, top=40, left=80')
fishWindow.focus()
}
</script>

<script language="JavaScript">

var tabs = [
//first tab
[
//tab image when unselected
'news.png',
//tab image when selected
'news_selected.png',
//tab data
'<p>This is the Basic tab</p>Basic Help<p><ahref="newpage.html">What is basic help?</a>'],

//second tab
[
'games.png',
'games_selected.png',
'<p>This is the Intermediate tab</p>Intermediate Help<p><a href="javascript:newWindow2('docs/web host help 1.html')">What is intermediate help?</a>'],
//third tab
[
'entertainment.png',
'entertainment_selected.png',
'<p>This is the Advanced tab</p>']];
//you can have more tabs if you want

//if you have empty space between your tabs, adjust this to a lower number
var width = 10;

function preloadImages() {
for (var y = 0; y < 2; y++) {
for (var x = 0; x < tabs.length; x++) {
image = new Image();
image.src = tabs[x][y];
}
}
}

function drawTabs() {
document.write("<table cellspacing=0 cellpadding=0 border=0><tr>");
for (var x = 0; x < tabs.length; x++) {
document.write("<td width="+width+"><a href='javascript:switchTab("+x+")'><img name='tab"+x+"' border=0 src="+tabs[x][0]+"></a></td>");
}
document.write("</td><td></td></tr><tr><td id=currentTab colspan="+(tabs.length+1)+">");
document.write(tabs[0][2]);
document.write("</td></tr></table>");
document.images["tab0"].src = tabs[0][1];
}

function switchTab(tab) {
for (var x = 0; x < tabs.length; x++) {
if (x != tab)
document.images["tab"+x].src = tabs[x][0];
}
document.images["tab"+tab].src = tabs[tab][1];
document.getElementById("currentTab").innerHTML = tabs[tab][2];
}

preloadImages();
</script>
</HEAD>

<BODY>

<script>
drawTabs();
</script>

</body>
</html>


The problem line is in blue; it's those single ' inside the ( ) that make the script not work. I've tried " " or ' ' or variations there, and nothing I try will get the tabs to both SHOW, and work.

Anyone know what to use here???

Jim Rudnick

jamescover
Sep 15th, 2004, 12:04 AM
You just need to escape the characters with a backslash "\":



<p>This is the Intermediate tab</p>Intermediate Help<p><a href="javascript:newWindow2(\'docs/web host help 1.html\')">What is intermediate help?</a>'


-james