Jump to content

Help edit JS


EchoFool

Recommended Posts

Hey

 

I have a form which is this:

 

 

<form method="POST" action="">
<input id="btn1" type="submit" name="test1" value="Test">
<input id="btn2" type="submit" name="test2" value="Test2">
<input id="btn3"type="submit" name="test3" value="Test">
</form>

 

What im trying to do is change my current JS which currently affects one button to now affect all 3 buttons! So all 3 will be disabled for 3 seconds on "page load" and show a animation of:

 

"

Wait.. 3

Wait.. 2

Wait.. 1

"                 

 

Then show its real button value as shown in the form when the timer expires. My current JS only works on one button which is this:

 

 

<script type="text/javascript">
var b = 0;
function counter() {
        var btn1 = document.getElementById('btn1');
        btn1.disabled = true;
        if (b < 2) {
                btn1.disabled = true;
                btn1.value = 'Wait... ' + (2-b);
                b++;
                setTimeout("counter()", 1000);
        } else {
                btn1.disabled = false;
                btn1.value = 'test1';
        }
}
window.onload = function() {
        counter();
}
</script>

 

Could you please help on how i can change it to affect all 3 buttons as my current script only works on one ?

Link to comment
Share on other sites

There may be a better way to do this but here is a quick and dirty(working) solution

 

var b = [];
var buttons = ["btn1","btn2","btn3"]
var btn = []
function counter(id,n) {
        btn[n] = document.getElementById(id);
        btn[n].disabled = true;
        if (b[n] < 2) {
                btn[n].disabled = true;
                btn[n].value = 'Wait... ' + (2-b[n]);
                b[n]++;
                setTimeout("counter('"+id+"',"+n+")", 1000);
        } else {
                btn[n].disabled = false;
                btn[n].value = 'test'+(n+1);
        }
}
window.onload = function() {
for(var i=0;i<buttons.length;i++){
	b[i] = 0;
	counter(buttons[i],i);
}
}

Link to comment
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.