Results 1 to 7 of 7

Thread: my script only works in firefox!

  1. #1
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default my script only works in firefox!

    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 \>

    Code:
    <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?

  2. #2
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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, 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?

    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

  4. #4
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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:
    Code:
     language="JavaScript" type="text/javascript"
    I will get the same error from Firefox. Is this a clue?

    Thanks for the help so far!

  5. #5
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    bump.

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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

  7. #7
    Join Date
    Sep 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    for future reference, the problem was this:
    Code:
    function setLang(num, class, class2)
    you cant use the word "class"

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •