How to Prevent User for Multiple click on form Submit button ?

Hi,Is there any easy solution rather than AJAX or any HARD Solution.to prevent user from being submit for only once...So database record remain consistent rather than redundant.if any JAVASCRIPT SOLUTION IT WOULD BE BETTER ONE.WHAT SHOULD I DO ?
[287 byte] By [Ghanshyama] at [2007-11-27 7:53:45]
# 1

This is a JavaScript question indeed, and definitely is not related to the server side.

Anyway, place a normal button, or a link, in your page to call a defined JavaScript function. For example:

<input type="button" onClick="submitForm()" />

or

<a href="javascript:submitForm()">SUBMIT</a>

I recommend the second one, since onClick and other mouse-related attributes make your code nonstandard. Define your function this way:

function submitForm() {

if (!submitted) {

document.forms[0].submit();

submitted = true;

}

}

"submitted" is a global variable, which must be set to "false" by default.

Arash.Shahkara at 2007-7-12 19:34:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks for codeBUT WHAT IF USER CLICK ON REFRESH BUTTON ?still data is inserted into database ....!!!!kindly provide waywhere to write code to databaseon submit page or on another page ?
Ghanshyama at 2007-7-12 19:34:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Your JSPs should only be a 'view'; only for displaying data.

All your database updating should take place in servlets.

You should look into asking the browser to not cache the page.

And since you're writing the code for the database entries, I don't think it'll be too difficult to verify that the data is not redundant. Primary keys anyone? :D

nogoodatcodinga at 2007-7-12 19:34:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
As i want , first all field must be validated before submitand then button will b greyedout ( disabled)how to do thatwhen i press submit.it will check for validation but not greyed out after that and submited
Ghanshyama at 2007-7-12 19:34:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Use the disabled property, set it to true and then submit the form programmatically.

<html>

<head>

<script>

function validate()

{

var textfield = document.getElementById('textfield');

var submitButton = document.getElementById('submitbutton');

var mainForm = document.getElementById('mainform');

if ( textfield.value.length == 0 )

{

alert("Validation Failed");

return false;

}

submitButton.disabled = true;

alert("The button has been disabled, going to submit now");

mainform.submit();

}

</script>

</head>

<body>

<form id="mainform" action="#" method="GET">

<input type="text" value="" id="textfield"/>

<input type="submit" value="Try Me!" id="submitbutton" onclick="return validate();" />

</form>

</body>

</html>

A reminder though, this is JavaScript and these are Java forums.

nogoodatcodinga at 2007-7-12 19:34:58 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...