SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change args in a function?

    say i have a function inside an image like this
    <img id="img1" onMouseOut="some_function(1)">

    so when the mouse leaves the image it called the function with the argument 1....but later an event can occur, and after that event occurs i need to change the arguement passed when that function is called from the onmouseout

    so is there a way to locate an argument being called from within an event(onmouseout) and change the value of the argument?

    so change onmouseout="some_function(1)" to onmouseout="some_function(3)" ????

    thanks
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  2. #2
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to consider setting an object property value instead of using a passed parameter.

  3. #3
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually what i did was just make the argument an array and then when that event happend assign a functoin to change the value of the array and it seems to work for now.

    what you suggested sounds interesting tho, how do you set an object property?
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's actually very easy to add a property to an object in JavaScript. Consider:

    var elem = document.getElementById('whatever'); // assign element to variable 'elem'
    elem.nprop = "hunh?"; // now the element object has a property 'nprop' with a value, the string 'hunh?'
    alert(elem.nprop); //returns 'hunh?'
    alert(typeof elem.nprop); //returns 'string'

    It gets a little trickier if you add the property through an attribute in the element's HTML tag (i.e. <div nprop="hunh?" ></div>). While some browsers' JavaScript interpreters will read that property using dot notation, many will require use of the W3C-approved getAttribute() method (A corresponding setAttribute() method can also be used to create new object properties in JavaScript, but at this time implementations of JavaScript support dot notation internally for the creation and reading of new properties).

    An advantage of object properties is that they are bound to the object and thereby easy to keep track of through the object. Additionally, they persist as long (and only as long) as the object persists.

    Just in case there is any confusion, (I used attribute and property somewhat interchangeably above), HTML attributes are element tag modifiers which set specific properties of the element object.
    Last edited by JVLB; Jun 15, 2006 at 20:11.

  5. #5
    Pragmatic Programmer halfasleeps's Avatar
    Join Date
    Feb 2006
    Location
    Altoona, PA. USA
    Posts
    1,945
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for the info
    Altoona Design
    Freelance Flex developer for hire.
    ActionScript Programmer with 8 Years Experience.


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
  •