Jump to content

Archived

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

play_

Easy question

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.