Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.