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 8 of 8
  1. #1
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts

    Unhappy passing a param from a function to another

    I have some difficulties to pass a parameter.
    I have some objects with same id, so I want to get them by order number let's say they are obj[i].

    I call first function on an event onevent="one(0)" in a place, onevent="one(2)" and so on

    function one(param){
    obj[param].style.attribute ="blabla";
    //so far so good, but from now once...

    somevariable = setInteval('two(param)',somenumberhere);//here is a mistake, by sure... but which?
    }

    function two(param){
    //no value passed???
    alert(param);
    obj[param]... and so on
    }

    I need the object in second function as well, but how can I pass the parameter in it?

    Any ideeas, please?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #2
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I suppose that param is a string. When you pass it to function one, it's only valid inside that function while setInterval executes code outside the functions. So put the value of param in setInterval instead:

    Code:
    setInterval('two("'+param+'")',somenumberhere);
    /Daniel

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    No, As I said, it is not a string... Anyway, I tryed, to be sure, the parseInt(param) but no use... . If I pass a definite number, yes, is OK, but I don't need to pass a certain value, I want to pass a value according to the event handler parameter....
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    Regular Coder
    Join Date
    Aug 2002
    Location
    São Paulo, Brazil
    Posts
    367
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, maybe I should start reading more carefully

    Let me first see if I got it now:
    You have some elements with the same id, so they become a collection (ie-only?). The elementcollection is global.

    So the only difference to what I wrote before would be to remove the double-quotes:
    Code:
    setInterval('two('+param+')',somenumberhere);
    If you call function one:
    one(0);

    the setInterval should looks like this at runtime:
    two(0);


    Somehow it feels like I didn't understand this time either.
    /Daniel

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    u tried writing:
    setInterval
    instead of:
    setInteval
    ?

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Yeees Sir, I got it... Even it looks strange to me at the first glance to write something like

    a_function('+0+')...

    But I got the sense, thank you
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    You could always have a look at <setInterval does not work as it is supposed to>. It's a method of doing things that might be a little hard to grasp, but it allows you to send things in other formats than as just a string.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    tack sa mycket, liorean... I saw that the main problem was not to pass a parameter, but to understand the setInterval() method
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

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