Jump to content


Photo

Easy question


  • Please log in to reply
2 replies to this topic

#1 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 01 April 2006 - 03:31 AM

I made a function that, calls another function after 1milisecond (its being used on a submit button, so when the button is pressed, it disables).

Anywyas, if i use this format, it works:
    function disable(id) {
        var obj = document.getElementById(id);
        obj.value='Loading. . .';
        obj.disabled=true;
    
    }
    

    function dis() {
        setTimeout('disable(1)', 1000)
        
    }

and the button:
<input type="submit" name="submit" value="Add this shirt" onmouseover="dis(1)" id="1" />


However, this is no good because on the 'dis' function, i hand-coded the '1' in there.

So ive been trying to pass a paremeter to dis(), and use that paremeter on:

setTimeout('disable(1)', 1000) <--- 1 here would be the paremeter passed.

So i tried this:

    function disable(id) {
        var obj = document.getElementById(id);
        obj.value='Loading. . .';
        obj.disabled=true;
    
    }
    

    function dis(num) {
        setTimeout('disable(num)', 1000)
        
    }

That way, dis() would call disable() with the paremeter of 1.
However, it keeps saying 'num' is not defined.

Any ideas?
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin

#2 play_

play_
  • Staff Alumni
  • Advanced Member
  • 717 posts

Posted 01 April 2006 - 03:42 AM

Edit. Found a solution. i had to type cast the paremeter.
in case anyone plan on using this script, here is the correct form:

    function disable(id) {
        var obj = document.getElementById(id);
        obj.value='Loading. . .';
        obj.disabled=true;
    }
    

    function dis(num) {
        id = Number(num)
        setTimeout('disable(id)', 1)
    }


enjoy
regex.kat.sh --- regex library
u.kat.sh ---- url shortener
tabbit.org ---- tabbed pastebin

#3 emehrkay

emehrkay
  • Staff Alumni
  • Advanced Member
  • 1,214 posts

Posted 02 April 2006 - 02:28 PM

if you're worried about validation, id change that id from a 1 to somethign that at least starts wilth a letter

and on the button you could have said 'this' instead of passing the id in




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users