...

View Full Version : disabling buttons after a submit



walltree
08-14-2008, 09:58 PM
What I'm looking for: I have a page that has multiple submit buttons on it. When the user clicks on a submit button, I need for two things to happen; 1-all submit buttons to be disabled and 2-the value of the submit button that the user clicked to stay in the value field so when the webpage returns control back to my program running in the background, it knows which button was clicked. My problem is when I go to disable all of the submit buttons using the following code:

function disablebuttons()
{
for(i=0; i<document.forms[0].elements.length; i++)
{
if (document.forms[0].elements[i].type == "submit" || document.forms[0].elements[i].type == "button")
{
document.forms[0].elements[i].disabled = "true";
}
}
document.forms[0].submit();
}

it disables all the buttons on the screen, but it also clears out all of their values so my background program has no clue which button was pressed. I can get around this by creating a hidden field on the webpage and calling the following code in the onclick() of each button:

function leaving2(btn)
{
document.forms[0].answer.value = btn.name;
disablebuttons();
}

I pass the name of the button clicked into this hidden field, disable the buttons, and then in my background program, I test against the hidden field to see which button was clicked. The only bad thing about this is that I have over 100 webpages and the process to add a new field onto each of those pages would be very time consuming.

So my question is: Is there a easier solution to where the value of the button clicked can stay intact despite it being disabled or am I stuck with my solution?

binaryWeapon
08-15-2008, 12:12 AM
Doesn't submitting a form refresh the page by default? The page refreshing could be the problem.

walltree
08-15-2008, 04:58 PM
My background program checks the values of the page before it is refreshed though. I've done the following to where if I had a button with an id of "btn1", I could automatically simulate that it was clicked by doing the following javascript:

document.forms[0].btn1.value = "go";document.forms[0].submit();

The above code works. When I go to disable all buttons on the screen so an impatient user can't double click, that's when the value is getting cleared out and I haven't found a way to put the value back in without having the button get reactivated.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum