Weird issue

Discussion in 'Javascript' started by Tom, Oct 22, 2005.

  1. Tom

    Tom Guest

    I've got a weird error that I just cannot figure out and hope that
    somebody has an idea of what to try next. I've got a global variable
    that I am assiging a new value to within a function which is tied to
    the onclick event of a html list. No javascript errors, etc. as a
    matter of fact I can "alert" the value of the global variable at the
    end of the function and sure enough it's contains the new value, and
    everything works like it should. Turn off the alert and the assignment
    doesn't happen?

    Just to add confusion, the global variable will actually contain the
    value of the previously clicked item in the list - if you click on the
    list a 2nd time on the same value, the global variable will "pick up"
    the correct value?


    Driving me nuts, any ideas?
     
    Tom, Oct 22, 2005
    #1
    1. Advertising

  2. Tom

    weston Guest

    Tom wrote:
    > No javascript errors, etc. as a matter of fact I can "alert" the
    > value of the global variable at the end of the function and sure
    > enough it's contains the new value, and everything works like it
    > should. Turn off the alert and the assignment doesn't happen?


    Are you saying that the alert gives you the correct value, or that
    the entire script works as expected?

    I'm still trying to get the hang of javascript scoping, but know it
    can be tricky and might be able to help if you put up an example.

    In the meanwhile, you could try putting the alert outside the scope
    of the function to make sure that the new assigned value is surviving
    outside of it, or see how it otherwise effects things.
     
    weston, Oct 22, 2005
    #2
    1. Advertising

  3. Tom

    Tom Guest

    If I alert the new value at the end of the function the new assignment
    takes effect globally, if I don't alert the value it doesn't get
    assigned globally until the 2nd time you click on the item in the
    list...
     
    Tom, Oct 22, 2005
    #3
  4. Tom

    Lee Guest

    Tom said:
    >
    >I've got a weird error that I just cannot figure out and hope that
    >somebody has an idea of what to try next. I've got a global variable
    >that I am assiging a new value to within a function which is tied to
    >the onclick event of a html list. No javascript errors, etc. as a
    >matter of fact I can "alert" the value of the global variable at the
    >end of the function and sure enough it's contains the new value, and
    >everything works like it should. Turn off the alert and the assignment
    >doesn't happen?
    >
    >Just to add confusion, the global variable will actually contain the
    >value of the previously clicked item in the list - if you click on the
    >list a 2nd time on the same value, the global variable will "pick up"
    >the correct value?


    The value isn't updated until after the onclick handler fires.
    Try using the onchange event, instead.
     
    Lee, Oct 22, 2005
    #4
  5. Tom

    web.dev Guest

    Tom wrote:
    > I've got a weird error that I just cannot figure out and hope that
    > somebody has an idea of what to try next. I've got a global variable
    > that I am assiging a new value to within a function which is tied to
    > the onclick event of a html list. No javascript errors, etc. as a
    > matter of fact I can "alert" the value of the global variable at the
    > end of the function and sure enough it's contains the new value, and
    > everything works like it should. Turn off the alert and the assignment
    > doesn't happen?
    >
    > Just to add confusion, the global variable will actually contain the
    > value of the previously clicked item in the list - if you click on the
    > list a 2nd time on the same value, the global variable will "pick up"
    > the correct value?
    >
    >
    > Driving me nuts, any ideas?


    Could you post the script (if it's small) or a url so we can actually
    see what's going on?
     
    web.dev, Oct 22, 2005
    #5
  6. Tom

    Tom Guest

    That did the trick - thank you so much, been banging my head on this
    one for a while.

    Thanks,

    Tom
     
    Tom, Oct 22, 2005
    #6
    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. dorayme
    Replies:
    1
    Views:
    650
    richard
    Jan 21, 2011
  2. richard
    Replies:
    0
    Views:
    610
    richard
    Jan 21, 2011
  3. richard
    Replies:
    0
    Views:
    640
    richard
    Jan 21, 2011
  4. Beauregard T. Shagnasty

    Re: A Weird Appearance for a Weird Site

    Beauregard T. Shagnasty, Jan 21, 2011, in forum: HTML
    Replies:
    1
    Views:
    459
    Captain Paralytic
    Jan 21, 2011
  5. David Segall
    Replies:
    0
    Views:
    646
    David Segall
    Jan 22, 2011
Loading...

Share This Page