Results 1 to 2 of 2

Thread: Update variables onclick

  1. #1
    Join Date
    Nov 2007
    Posts
    151
    Thanks
    67
    Thanked 0 Times in 0 Posts

    Default Update variables onclick

    Hi I have simple int variable in javascript.
    I want to change it's value when I click on some link.

    How can I do it?

    Thanks!
    Last edited by d-machine; 10-21-2009 at 10:48 PM.

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    There is no such thing (technically speaking) as a simple variable. The closest thing would perhaps be a global variable. If that's what you have, it can be changed in an onclick event without much trouble. Let's say, as could be construed from your post, that the name of this variable is int:

    Code:
    onclick="int = 5;"
    Now, of course, if this is a link, one should return false.

    In the above I've set it to the number 5. It could just as easily be set to a string, boolean, object, etc.

    But, even with a global, if it has already been put into another scope, depending upon the situation (like as part of an interval), though its value will change, its value in the interval will not.

    If it is not a global, unless it has some way of being referenced from the global scope (like being a part of an object in the global scope), you might not be able to access it from an onclick event.

    So if you are still having problems, please be more specific and post a link to your page where this is an issue.
    Last edited by jscheuer1; 10-22-2009 at 04:44 AM. Reason: be more precise
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

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
  •