Jump to content

Easy question


play_

Recommended Posts

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:
[code]
    function disable(id) {
        var obj = document.getElementById(id);
        obj.value='Loading. . .';
        obj.disabled=true;
    
    }
    

    function dis() {
        setTimeout('disable(1)', 1000)
        
    }[/code]

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:

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

    function dis(num) {
        setTimeout('disable(num)', 1000)
        
    }[/code]

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

Any ideas?
Link to comment
https://forums.phpfreaks.com/topic/6316-easy-question/
Share on other sites

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

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

    function dis(num) {
        id = Number(num)
        setTimeout('disable(id)', 1)
    }[/code]


enjoy
Link to comment
https://forums.phpfreaks.com/topic/6316-easy-question/#findComment-22810
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.