SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    fill select menu - works on IE6 not NS6

    I have this tiny little javascript:

    function buildselect() {
    parent.center.dpreply.drop.options[0] = new Option('- - - Categories - - -', '');
    parent.center.dpreply.drop.options[1] = new Option('asd', '1');
    parent.center.dpreply.drop.options[2] = new Option('testing 2', '2');
    }
    which is in one frame and I call it from another frame to fill a select menu using:

    window.top.topbar2.buildselect();

    In IE6 this works fine, in NS6 nothing is displayed. What am I doing wrong?

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    does NS6 support the 'Option' object? it might not.

  3. #3
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    um.. well if not how do you fill a dropmenu with some values? Seems weird it would not support that object dosen't it? As you can tell i am quite new to javascript

  4. #4
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is a super lame workaround, but you can build a string and insert it into a div or span tag. i don't know if you are building dynamically or not. if you are, just insert a loop for the for the 'options' part ex:

    function buildDropdown() {
    var sDrop;
    var aOptions = new Array();
    var i;

    sDrop = "<select id=\'dpreply\'>";

    for(i=0; i<10; i++) {
    aOptions[i] = "<option value=\"" + i + "\">test" + i + "</option>";
    }

    divYourDivTag.innerHTML = sDrop + aOptions.join("") + "<select>";
    }

    The reason that i am building an array and then joining it is that it is much faster than building a string(MSDN). However, if NS does not support arrays or joins that well, you can skip the array/join, create a big string and insert it.

  5. #5
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't really do that because the drop down menu has to be updated dynamically. I basically have one frame with the data in it (dynamically generated) and another frame with some links that fill in that data. The links call the appropriate function in the "data" frame.

  6. #6
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry, i don't follow. but, if you can make it work with the option object, you can make it work with the string. the same way that you supply the values for your object, you need to get them into the string.

    sorry if this doesn't help much but its hard for me to conceptualize what you're doing.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2002
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You simply need to use "document" to return a document object in NS6,



    <html>
    <head>
    <title>Untitled</title>
    <script>

    function xalert(){

    document.formx.optionx.options[5] = new Option('- - - Categories - - -', '');

    alert(document.formx.optionx.length)

    }

    onload = xalert;
    </script>



    </head>

    <body>

    <form name="formx">

    <select name="optionx">
    <option value="1" SELECTED></option>
    <option value="2"></option>
    <option value="3"></option>
    <option value="4"></option>
    <option value="5"></option>
    </select>

    </form>

    </body>
    </html>




    So your crossframe code would go something like...

    function buildselect() {
    parent.center.document.dpreply.drop.options[0]
    }

  8. #8
    SitePoint Evangelist
    Join Date
    Feb 2000
    Location
    England
    Posts
    568
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    original post edited if you read it

    I see what you mean, change:


    parent.center.dpreply.drop.options[0]

    to

    parent.center.document.dpreply.drop.options[0]

    and yup, that now works perfect ony NS6 and IE6

    Thanks!
    Last edited by padders; Mar 6, 2002 at 13:10.

  9. #9
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    good to know, thanks!


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
  •