Two web site coding questions (inc. Javascript)

A couple of problems, any help appreciated !

1 – I’d like to move this kind of rollover info into a separate (presumably) text or html file and call it into the page from there:

<td><a href=“http://etc” onMouseOut=“MM_swapImgRestore();FW_startTimeout();” onMouseOver=“window.FW_showMenu(window.fw_menu_0,0,164);MM_swapImage(‘a’,’’,‘one/two/three.gif’,1);” ><img name=“a1” src=“one/two/three-1.gif” width=“120” height=“26” border=“0”></a></td>

Just can’t think of the way to go about doing this.
2 – Also, I’m crap with Javascript and so used a freebie ‘todays-the-day’ script. However, I’d like the option of changing the font, colour and text size. I’m pretty sure it’s only a few lines…can someone help me out, pleaseeeee ?

Here’s the code if it’s of any help:

*<!-- Begin
dayName = new Array("", “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”, “Sunday”)
monName = new Array(“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”)
now = new Date
// End →

<!-- Begin
var strDay;
if ((now.getDate() == 1) || (now.getDate() != 11) && (now.getDate() % 10 == 1)) // Correction for 11th and 1st/21st/31st
strDay = "st ";
else if ((now.getDate() == 2) || (now.getDate() != 12) && (now.getDate() % 10 == 2)) // Correction for 12th and 2nd/22nd/32nd
strDay = "nd ";
else if ((now.getDate() == 3) || (now.getDate() != 13) && (now.getDate() % 10 == 3)) // Correction for 13th and 3rd/23rd/33rd
strDay = "rd ";
else
strDay = "th ";
document.write(
dayName[now.getDay()]
+
" the "
+
now.getDate()
+
strDay
+
"of "
+
monName[now.getMonth()]
+
", "
+
now.getFullYear()
)
// End →
*

How would you go about that ?

Cheers !

For the first question, i would use Javascript of includes to get this done. However, I am no expert at either (went right past that and on to ASP) and hopefully someone can get you some insight. In most of the coding I do, we use a javascript script to make the function (which you probably already have) and always end up writing out al of that stuff.

For the second question, see the line that has document.write? That is where it begins writing the date and stuff. the + is concatinating (??) the variables. So you have day + “the” + date + “of” etc.

Put your font tags in there like this:

etc…

I put two font tags in there to show you how to change the font for every element if you want to.

Hope that helped.

Why do you want that seperate?

I need to get a little more disciplined/precise about optimising the pages for search engines. By putting these in a separate file and excluding the spiders, I get a much more precise measurement for keyword placement, prominence, %, etc.

Any suggestions :slight_smile:

Are you being hosted on a Windows NT server? If so, you could use ASP to make those.

A function would be like:

Function ImageSwap(url, imgName, imgSource, imgSource2, width, height)

Response.Write “<a href=”<%=url%>" onMouseOut=“MM_swapImgRestore();FW_startTimeout();” onMouseOver=“window.FW_showMenu(window.fw_menu_0,0,164);MM_swapImage(’<%=imgName%>’,’’,”<%=imgSource2%>’,1);" ><img name="<%=imgName%>" src="<%=imgSource%>" width="<%=width%>" height="<%=height%>" border=“0”></a>
End Function

To call the function you would do:

Call ImageSwap(www.url.com, a, one/two/three-1.gif, one/two/three.gif, 120, 26)

and it would print all that out and input the values you need.

If you aren’t on an NT server, well then someone is going to have to help you write some javascript :slight_smile:

Er, add a " after that </a> in the function.

Also, check out www.4guysfromrolla.com and www.asp101.com for more help with asp.

You know, that’s an idea ! Hadn’t thought of ASP but as some of this site will be dynamic it might well make sense.

Only problem I might have is that search engine’s spider (I’m rusty so I’ll need to look at this also) up to the first ? in the string - which would pretty well negate the original purpose. However, things could well have moved on.

A nice suggestion. Cheers Zipper !

Just create a new file with the extension .js

In the file, write this:



var x;

x = "<td><a href='http://etc' "
x += "onMouseOut='MM_swapImgRestore();FW_startTimeout();' "
x += "onMouseOver='window.FW_showMenu"
x += "(window.fw_menu_0,0,164);"
x += "MM_swapImage('a','','one/two/three.gif',1);' >"
x += "<img name='a1' src='one/two/three-1.gif'"
x += "width='120' height='26' border='0'></a></td> "

document.write(x)


Then, in your html page, where you want the 's to appear:



<SCRIPT LANGUAGE="JavaScript" SRC="Filename.js">
</SCRIPT>


Just make sure you put single quote marks within the double quote marks, and if you need to put a quote within a quote, do something like this:

Thanks for your help guys…
Zipper - I had real trouble putting into practice what you suggested. Just couldn’t make it happen…however ! I was playing around and chanced across the simplest option of all (given that I want to change stuff universally). I guess you’ll know the move but…just put a font tag around the script on the page:

      &lt;TD&gt;

<FONT face=“Arial, Helvetica, sans-serif” color="#003399"><B>
<script language=“JavaScript” src=“whatever/js/date.js”></script></B>
</FONT>
</TD>

  • so damn simple ! Thanks for the help, though !

** Starbury** - Thanks for the time you took. Got a problem, though. Played around with it a lot. What I do have is the buttons on the page from the .js file and the active links work. That’s a start !!

The main issue is the mouseovers – not sure if I can’t tell whether the pop up javascript menu will activate until I resolve the mouseover issue. If you see this and get a minute, would you quickly look at this for me ?:

var x;

x = "<td><a href=‘http://etc’ "

x += "onMouseOut=‘MM_swapImgRestore();FW_startTimeout();’ "

x += “onMouseOver='window.FW_showMenu”

x += “(window.fw_menu_0,0,164);”

x += “MM_swapImage(‘London’,’’,‘Calling/NavBar/1_over.gif’,1);’ >”

x += "<img name=‘London’ src=‘Calling/NavBar/1.gif’ "

x += "width=‘120’ height=‘26’ border=‘0’></a></td> "

document.write(x)

  • BTW, I have five consecutive sets in the same file, all beginning with var x; and ending with document.write(x) – I’m getting a lot of ‘errors on the page’ stuff from the browser :slight_smile:

I understand this might be time consuming so it’s not a problem if you’re busy. Cheers for your help !

Ok, the only (potential) problem I found with this was the part that I bolded. Unfortunately, I can’t type out the proper code on the SDMB, because it keeps parsing everything out when I submit it. Basically what you need to do is put the whole onMouseOver section of the tag onto one line. Like this:

**
x += "onMouseOver=‘window.FW_showMenu
(window.fw_menu_0,0,164);
MM_swapImage(‘London’,’’,‘Calling/NavBar/1_over.gif’,1);’ **

(ok it doesn’t show up as one line on here, but in your HTML editor you would have it all on one line)

Next, because you’re going to have quotes within quotes within quotes, start it out with a single quote for the entire variable value, and use double quotations for the function calls:

x += 'onMouseOver=window.FW_showMenu
(window.fw_menu_0,0,164);
MM_swapImage(‘London’,’’,‘Calling/NavBar/1_over.gif’,1);
'

Then, in the MM_swapImage you have another set of quotes, so you need to use an escape character there in front of every single quote that you use around the values being sent into the function:

x += ‘onMouseOver="window.FW_showMenu
(window.fw_menu_0,0,164);
MM_swapImage(**'London*’,*****’,*'Calling/NavBar/1_over.gif***’,1);" ’

One thing that you can do to avoid this (other than using different variable names for each function) is set up a variable at the beginning of the first script you use, outside of any functions.

So you might have

<SCRIPT Language=“JavaScript”>
<!–

var x;

function blah(){

x=somevalue;

};

function blah2(){

x=someothervalue;

};

</SCRIPT>

Probably not the best way to manage memory on the client’s computer but it should get rid of the errors at least.
If that whole bit about the quotations didn’t work out for you (or more likely I didn’t explain it clearly enough) you can email me at cardinalzin@excite.com and I will send you the .js file as I would have written it.