Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    May 2003
    Location
    Toronto
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Triggering onChange/Dropdown

    Another problem...

    I have a double combo box working fine with javascript. What I would like to do is to be able to select/change the first combo box from a menu or from somewhere besides actually choosing an item in the drop down menu.

    The problem is that when I got to change it using the DOM the second combo box is NOT updating it's value the way it should be. The function for the combo box is originally called using the onChange="function(this)" command.

    Is there a way to trigger the onChange somehow? Whenever I send a value into the function directly the second combo box never updates.

    Here's the function:

    function productselected(elem){
    for (var i = document.f1.productLine.options.length; i >= 0; i--){
    document.f1.productLine.options[i] = null;


    Any help would be greatly appreciated. Thanks.

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can call an HTML event handler explicitly:

    ref_to_select.onchange();

    Hard to tell if this is helpful.

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    or after changing the select, call the onchange function manually.

  • #4
    New Coder
    Join Date
    May 2003
    Location
    Toronto
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The problem I'm having is the form originally uses:

    onChange="function(this)";

    and I'm not sure exactly what value 'this' is sending to the function so I'm not sure what value to send. I'm trying all kinds of different combinations but with no success.

  • #5
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    using "this" in function definition

    It's not a value - it's the Select object. Did you try calling it explicitly (above)?

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,037
    Thanks
    0
    Thanked 250 Times in 246 Posts
    functionToCall(document.formName.selectName)

  • #7
    New Coder
    Join Date
    May 2003
    Location
    Toronto
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was able to grab some help and I think the problem is solved. I'll post the script so other people can use it if they run into the same problem.

    I really do appreciate your help and patience though Cheesebagpipe and Glenngv.

    <html>
    <head>
    <title>Untitled</title>
    <script type="text/javascript">
    <!--
    function see(sel) {
    alert(sel.value)
    }
    function activateOnChange() {
    var s = document.forms["ff"].elements["ss"]
    s.fireEvent("onchange")
    }
    // -->
    </script>
    </head>
    <body>

    <form action="" name="ff">
    <select onchange="see(this)" name="ss">
    <option value="111">aaaaa</option>
    <option value="222">bbbbb</option>
    </select>
    <a href="#" onclick="activateOnChange()">Activate onChange</a>
    </form>
    </body>
    </html>

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You're using IE-only DHTML behaviors. With so many ways to do this, why choose a proprietary one?

  • #9
    New Coder
    Join Date
    May 2003
    Location
    Toronto
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yikes.. I didn't realize that..

    Okay.. I did try calling the function using your syntax above:

    document.f1.alloy.onChange();

    which came back with an error.

    I also tried calling the function and passing in a value as Glenngv suggested but also had no luck:

    alloyselected(document.f1.alloy);

    I feel like a damn moron.. Obviously I'm looking for a non-browser specific answer. The way I got the previous IE only function to call was to put it in the onLoad handler so each time the page is refreshed it will automatically do it.. and that seemed to work fine.

    I'm baffled and frustrated (as I'm sure you are with my babbling )..

  • #10
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Look, you babbling moron ( )

    document.f1.alloy.onchange();

    If that don't cut it, post some of the relevant code, along with some more moronic babbling...

  • #11
    New Coder
    Join Date
    May 2003
    Location
    Toronto
    Posts
    59
    Thanks
    0
    Thanked 0 Times in 0 Posts
    LOL..

    [BABBLE]

    a sense of humour is becoming the only thing keeping me going.

    Okay.. I think what you just gave me is working.. I'm sure I tried that at some point during my 16 hours of coding yesterday.. But of course what actually happened past hour 12 is anybody's guess.

    .EDIT.

    Netscape = bad.. Now that IE works fine.. It's on to tackle Netscape which should be next to impossible . .. crap

    [/BABBLE]
    Last edited by loomer; 06-05-2003 at 07:33 PM.


  •  

    Posting Permissions

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