Archive for January, 2008

javascript disable and form submit buttons

January 31, 2008

Had a form with multiple submit buttons which I was using to give the user different options as to what page the user would go to after the form was processed. Had a problem with users clicking the submit button more than once (and therefore data was being duplicated), so I put in a javascript to disable all the buttons after one of them was clicked once. Got a bug report soon after that the page the user was going to was the same no matter which of the submit buttons was being pressed.

The cause of the problem was that the “value” of whichever submit button was pressed wasn’t being submitted once the button was disabled. The solution was to create a hidden field to hold the value I was sending via the different submit buttons, and change the submits to plain buttons with an onclick attribute that set the value of the hidden field before submitting the form.