...

View Full Version : Can someone help me with a function?



pankirk
06-27-2009, 04:27 AM
I have this problem. I want to make it so a user can't click a button more than once on a web page, so I have javascript where the button gets disabled and the text of the button gets changed to "submitting..."

Now, I made this by myself:
<input type="submit" id="submitButton" onClick="this.disabled=true; submitButton.value='Submitting...';" />

But I would really like it in a function so that on any button I can call the function like "disable(buttonId)" or something like that. So I was just wondering If someone can show me how I can write that function, or crank a quick one out for me? Thanks.

Old Pedant
06-27-2009, 04:36 AM
Ummm...I think you already wrote the code. You just need to turn it into a function.



<script>
function once(which)
{
which.disabled = true;
which.value = "Submitting...";
}
</script>
...
<input ... onclick="once(this);">
...

Quite frankly, I don't see the need for a function for this, as more than likely you will want to use a different value for each button, to match its original value.

Were you also asking how to attach that handler to all submit buttons??

pankirk
06-27-2009, 04:41 AM
Hmm well thats all I really wanted. Thanks!

But when i do
<input type="submit" onClick="once(this)" />

the nothing is submitted and the page is reloaded. Any tips?

ckeyrouz
07-02-2009, 07:47 PM
<input type="submit" onClick="once(this)" />
let this code be like this:
<input type="button" onClick="once(this);document.theform.submit()" />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum