SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast Vman's Avatar
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Opera Select selected index

    Hi All,

    I have a document that uses the following javascript code to let me know what the currently selected index of a select box is.

    PHP Code:
    document.<form_name>.<select_name>.selectedIndex 
    This works fine in IE though it doesn't work in Opera - I have had a look around and can't find a replacement or workaround for this.

    Does anyone know of any solutions?

    Many Thanks.

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work, can you post the url?
    ck :: bringing chris to the masses.

  3. #3
    SitePoint Enthusiast Vman's Avatar
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't post a link as it isn't on the internet.

    The page is the top part of a two row frame.
    Here is the code:


    <script>
    function nextsite() {
    maxposition = document.browselinks.browseoptions.length;
    curposition = document.browselinks.browseoptions.selectedIndex;
    if (curposition!=(maxposition-1)) {
    curposition++;
    document.browselinks.browseoptions.selectedIndex = curposition;
    //parent.content.location.href=document.browselinks.browseoptions.selectedIndex.value;
    parent.content.location.href=document.browselinks.browseoptions.options[document.browselinks.browseoptions.selectedIndex].value;
    }
    }

    function prevsite() {
    curposition = document.browselinks.browseoptions.selectedIndex;
    if (curposition>0) {
    curposition=curposition-1;
    document.browselinks.browseoptions.selectedIndex = curposition;
    parent.content.location.href=document.browselinks.browseoptions.selectedIndex.value;
    }
    }


    </script>
    </head>

    <body>
    <table>
    <tr>
    <td valign="top">
    <a href="#" onClick="prevsite();">Previous Site</a>
    </td>
    <td>
    <form name="browselinks" action="">
    <select name="browseoptions" onChange="parent.content.location.href = this.options[this.selectedIndex].value;">

    <option selected></option>
    <option value="http://link1.com">This is link1</option>
    <option value="http://link2.com">This is link2</option>
    <option value="http://link3.com">This is link3</option>
    </select>

    </form>
    </td>
    <td valign="top">
    <a href="#" onClick="nextsite();">Next Site</a>
    <!-- document.browselinks.browseoptions.selectedIndex -->
    </td>
    <td>
    <script>
    var value1=document.browselinks.browseoptions.length;
    var value2 = document.browselinks.browseoptions.selectedIndex;
    document.write(value1);
    document.write(value2);

    //This is a test to see if the selected index works in Opera
    </script>
    </td>

    </tr>
    </table>
    Hope this makes it clearer.

  4. #4
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The transfer line (parent.content.location.href=...) in prevsite() is wrong, it should be the same as the one in nextsite().
    ck :: bringing chris to the masses.

  5. #5
    SitePoint Enthusiast Vman's Avatar
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That bit works fine - it is the code:
    document.<form_name>.<select_name>.selectedIndex

    that doesn't work in Opera.

  6. #6
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, that part works fine. What line are you talking about?
    ck :: bringing chris to the masses.

  7. #7
    SitePoint Enthusiast Vman's Avatar
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The bit here:
    <script>
    var value1=document.browselinks.browseoptions.length;
    var value2 = document.browselinks.browseoptions.selectedIndex;
    document.write(value1);
    document.write(value2);

    //This is a test to see if the selected index works in Opera
    </script>
    In Opera I generally get undefined for value2 - thought in IE it will say 0


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
  •