PDA

View Full Version : my script only works in firefox!



crazedcougar
09-09-2006, 07:23 PM
While I was writing I only tested with firefox, it works well on there! However, nothing happens on other browsers.

This code is to change the text in a <P> or <A> tag to a different button. The below script is placed in the header, and run via these:

<body onLoad="setLang(getCookie('lang'), 'selected', 'borderit')">

<a class="borderit" id="1" href="#" onclick="setLang('1', 'selected', 'borderit')"><img src="flag.gif" width="30" alt="en"></a><br \>


<SCRIPT language="javascript">
function setCookie(c_name,value,expiredays){
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate)
}
function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return null
}

function setLang(num, class, class2) {
var str1
var str2
document.getElementById(num).blur()
setCookie('lang', num, '100');
for(i=1;i<6;i++){
identity=document.getElementById(i);
identity.className=class2;
}
identity=document.getElementById(num);
identity.className=class;
// graphics done - start text
if (num == 1) {
str1 = "text here"
str2 = "text here"
}
else if (num ==2) {
str1 = "text here"
str2 = "text here"
}
else if (num ==3) {
str1 = "text here"
str2 = "text here"
}
else if (num ==4) {
str1 = "text here"
str2 = "text here"
}
else if (num ==5) {
str1 = "text here"
str2 = "text here"
}
document.getElementById('blurb1').innerHTML=str1
document.getElementById('blurb2').innerHTML=str2
}
</script>

In IE or safari, when clicked they dont become selected, and the strings do not get defined.

You can view a working example here: (no I'm not trying to hype the site)
http://routetruck.com/danEhrlich/index.html
Try it in Firefox, then Internet explorer or safari.

Thanks!
--Peter
PS, is there any good software like firebug that can get errors from IE or safari?

crazedcougar
09-09-2006, 08:23 PM
aha! I've finally found IE's debugging tool, and have narrowed it down to this:

onLoad="setLang(getCookie('lang'), 'selected', 'borderit')"

or, in the case of the flags, this:

onclick="setLang('1', 'selected', 'borderit')"

commenting out everything inside the setLang does not fix the problem, however remove these onclick attributes does.


It gives one other error. It says it expects an Identifier on the first letter of "class".
function setLang(num, class, class2) {

:-/

--Peter

mwinter
09-09-2006, 11:39 PM
Stop what you are attempting. Do not use scripting to provide language variants; they should be available as separate documents. Start by reading Techniques for multilingual Web sites (http://www.cs.tut.fi/~jkorpela/multi/index-en.htm), a series of articles by Jukka Korpela.

Whilst you are rewriting, consider using modern, semantic markup.



id="1"

An id attribute value must begin with a letter.



<br \>

What on Earth?



http://routetruck.com/danEhrlich/index.html

Your attempt to set content type using meta elements is very confused. First of all, you aren't writing XHTML, so I have no idea why the second element is present. More importantly, however, your server is already sending content type data, which is not only authoritative, but wildly different from what you are trying to set.

Mike

crazedcougar
09-10-2006, 12:48 AM
Fixed the ID names, fixed the breaks, fixed the meta content. Still the same error.

"Error: Object Expected"
>.<

If I remove from the script tags:

language="JavaScript" type="text/javascript"
I will get the same error from Firefox. Is this a clue?

Thanks for the help so far!

crazedcougar
09-14-2006, 08:19 PM
bump.

mwinter
09-17-2006, 08:18 PM
If you had followed my advice, you wouldn't still be having problems. You shouldn't use scripting for this, so don't. The reason why the code fails then becomes irrelevant.

Mike

crazedcougar
09-17-2006, 08:57 PM
for future reference, the problem was this:


function setLang(num, class, class2)

you cant use the word "class"