/    Sign up×
Community /Pin to ProfileBookmark

Prevent submit until response is returned

Hi,
I am new to javaScript so I hope I can get some help here.

I have a page where I want to avoid the user to submit more than once
before the server has responded. I do this by calling a javascript function
when my form is submited.

[code=html]<form action=”/maps/main.do” name=”form1718″ method=”post” onSubmit=”return validateSubmit()”>[/code]

This works fine when I press the different buttons on the page.

[code=html]<input id=”button_save” type=”submit” name=”cmd” value=”Save” class=”button”/>[/code]

But when I press an icon that is supposed to delete a record in
the database I can press a button before the response is returned.

[code=html]<a href=”#” name=”cmd” onclick=”deleteTrans(0)”><img border=”0″ src=”imagesikon_soptunna.gif”/></a>[/code]

The javaScript function looks like this:

[CODE]<script language=”JavaScript”>
var bSubmitOverride = false;

function validateSubmit()
{
alert(“bSubmitOverride: ” + bSubmitOverride);
if (bSubmitOverride)
{
alert(“Var god dröj…Väntar på svar från servern.”);
return false;
}
else
{
bSubmitOverride = true;
return true;
}
}

function deleteTrans(radnr)
{
if(validateSubmit())
{
document.forms[0].elements[‘delete’].value= radnr;
popupWindowNew(${param.windowId}, ‘remove’, ‘remove’);
if(document.forms[0].elements[‘remove’].value==’J’)
{
bSubmitOverride = true;
}
else
{
bSubmitOverride = false;
}
}
}
</script>[/CODE]

When I press the icon first and then press a button the bSubmitOverride
variable dose not seem to have been set to true. ?
Can someone please help?

Thanks in advance! ?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliApr 08.2006 — it looks like you are using Java (probably struts) for your server side, if thats the case then the method in the java code which actually deletes or updates the database make sure that you use keyword synchronized with it so that its thread safe.
Copy linkTweet thisAlerts:
@LIRAauthorApr 10.2006 — Hi,

Thanks for your replay, Khalid!

I use Spring. How can I solve this in Spring?
×

Success!

Help @LIRA spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...