Javascript code only works in Netscape, yet no Scirpt error???

Discussion in 'Javascript' started by John, Apr 8, 2005.

  1. John

    John Guest

    Code is as follows:

    document.write('<FORM name="horseform">');
    document.write(' <SELECT SIZE="1" NAME="horsebrandslist" STYLE="font-size:
    8pt">');
    document.write(' <OPTION VALUE="http://my.domain.com/cat1.html">Category
    1</OPTION>');
    document.write(' <OPTION VALUE="http://my.domain.com/cat2.html">Category
    2</OPTION>');
    document.write(' <OPTION VALUE="http://my.domain.com/cat3.html">Category
    3</OPTION>');
    document.write(' </SELECT>');
    document.write(' <a href="javascript:;" title="Click here"
    onclick="goto_PetCategoryURL(document.horseform.elements.horsebrandslist)"><img
    border="0" src="../images/horse/someimage.gif" width="29" height="20"
    alt="Click here" align="absbottom"></a>');
    document.write('</FORM>');


    In a separate .js file, the function "goto_PetCategoryURL" looks like this:

    function goto_PetCategoryURL(object) {
    if (object.selectedIndex > 0) {
    window.location.href = object.options[object.selectedIndex].value;
    }
    return;
    }


    In Netscape (I use version 7), all works OK. In IE or Opera, when I click
    the image, nothing happens. No error shows in the Opera JavaScript Console
    or the bottom left of IE.

    Who can solve this mystery?

    Thanks,
    Don
     
    John, Apr 8, 2005
    #1
    1. Advertising

  2. John

    Lee Guest

    John said:
    >
    >Code is as follows:
    >
    >document.write('<FORM name="horseform">');
    >document.write(' <SELECT SIZE="1" NAME="horsebrandslist" STYLE="font-size:
    >8pt">');
    >document.write(' <OPTION VALUE="http://my.domain.com/cat1.html">Category
    >1</OPTION>');
    >document.write(' <OPTION VALUE="http://my.domain.com/cat2.html">Category
    >2</OPTION>');
    >document.write(' <OPTION VALUE="http://my.domain.com/cat3.html">Category
    >3</OPTION>');
    >document.write(' </SELECT>');
    >document.write(' <a href="javascript:;" title="Click here"
    >onclick="goto_PetCategoryURL(document.horseform.elements.horsebrandslist)"><img
    >border="0" src="../images/horse/someimage.gif" width="29" height="20"
    >alt="Click here" align="absbottom"></a>');
    >document.write('</FORM>');
    >
    >
    >In a separate .js file, the function "goto_PetCategoryURL" looks like this:
    >
    >function goto_PetCategoryURL(object) {
    > if (object.selectedIndex > 0) {
    > window.location.href = object.options[object.selectedIndex].value;
    > }
    > return;
    >}


    1. You've got no way of going to cat1.html, since selectedIndex
    for that choice is 0.

    2. Your onclick handler should return false:
    onclick="goto_PetCategoryURL(...);return false"
     
    Lee, Apr 9, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dbuchanan
    Replies:
    9
    Views:
    4,171
    Jim Wooley
    Feb 8, 2006
  2. Berehem
    Replies:
    4
    Views:
    564
    Lawrence Kirby
    Apr 28, 2005
  3. foren_de

    Tabstrip works only with Netscape

    foren_de, May 27, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    91
    foren_de
    May 27, 2004
  4. Randy Weber
    Replies:
    1
    Views:
    121
    Martin Walke
    Oct 28, 2004
  5. NNTP
    Replies:
    14
    Views:
    211
    Beardy
    Feb 11, 2004
Loading...

Share This Page