SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Est
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    script works only when alert is called

    I use script described here for making dynamic selectboxes (user selects something in the first box, then the options in the second box change automatically).

    There was tiny problem - after form submitting was selected first option in right selectmenu (although there was selected="selected" on other option). I fixed it almost , now it works with Firefox and Opera 8, but i noticed that with IE 6 it works only when there was called alert() function :/

    Examples (use IE for testing):
    with alert (works)

    without alert (doesn't work)

    Here is commented source of this javascript file

    What may be solution for this strange problem?

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,439
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    script

    The "non-working" example works for me using IE 6 Windows OS with javascript version 1.3 support

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Usually when something works with an alert but not without, it's a timing issue (like the script is being called before the page finishes loading).

    To fix this normally put function calls in the window.onload event handler.

    I didn't look so I don't know if that's the problem, but it usually is

  4. #4
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Est
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague
    The "non-working" example works for me using IE 6 Windows OS with javascript version 1.3 support
    I tested with 3 computers and all failed (all OSes was windows xp (sp1, sp2 and no sp) with IE v6).. was there selected "#estonian" on right dropdown menu?

    Quote Originally Posted by jimfraser
    Usually when something works with an alert but not without, it's a timing issue (like the script is being called before the page finishes loading).

    To fix this normally put function calls in the window.onload event handler.

    I didn't look so I don't know if that's the problem, but it usually is
    Yes, there is already called window.onload:
    Code:
    window.onload = function() {
    	dynamicSelect("srv", "chn");
    }
    and this works too (it removes all options and adds what necessary) but it doesnt highlight selected as needed.

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,439
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    retraction

    Sorry, I misunderstood the problem. I thought you meant the channel select didn't change with changes to the server select.
    So, no, it doesn't work in IE.
    I'm curious, if you temporarily hard code the alert (instead of having PHP conditionally echo it), is the behaviour the same? (my guess is yes, I'm just curious)
    HTML Code:
    if(clonedOptions[i].value==selVal)
                {
                    alert(selVal);
                    sel2.value = selVal;
                }
    I don't know if it might be related to the IE appendChild bug
    http://www.dynamicdrive.com/forums/s...ead.php?t=5960
    where the poster had to use a text node.
    Or maybe it has something to do with IE and the "clones".

  6. #6
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Est
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague
    I'm curious, if you temporarily hard code the alert (instead of having PHP conditionally echo it), is the behaviour the same? (my guess is yes, I'm just curious)
    Yes, its same, at the beginning i added it without php..
    Quote Originally Posted by Mittineague
    HTML Code:
    if(clonedOptions[i].value==selVal)
                {
                    alert(selVal);
                    sel2.value = selVal;
                }
    I don't know if it might be related to the IE appendChild bug
    http://www.dynamicdrive.com/forums/s...ead.php?t=5960
    where the poster had to use a text node.
    Or maybe it has something to do with IE and the "clones".
    I tried to add these options with createTextNode like in this thread You linked, but unfortunately this works similary (only with alert)..

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,439
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    attack of the clones

    It must have something to do with the way browsers handle clones, memory, page rendering and onload events.
    I notice that "estonian" doesn't happen until after the alert is closed.
    Currently the alert is accessing a DOM value. Does it still behave the same if you simply alert text? eg
    Code:
     alert("show estonian!");

  8. #8
    SitePoint Member
    Join Date
    Apr 2004
    Location
    Est
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I added this selVal into setTimeout
    Code:
    if(clonedOptions[i].value==selVal)
    {
    	setTimeout(function(){
    		sel2.value = selVal;
    }, 500);
    }
    and seems that now it works

    Thanks.

  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    16,439
    Mentioned
    160 Post(s)
    Tagged
    1 Thread(s)

    select bug

    Well pragmatically that is a good solution. Whether it's a matter of loading or memory threading or whatever, we may never know. But until (if ever) IE gets up to standards, it's good to find work-arounds, no matter how cludgy. Thank you for posting your fix.


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
  •