David Williamson
asked on
Clicking cancel on confirm prompt submits anyway
I have the following script:
<script type="text/javascript">
function confirmOverwrite(question) {
var do_ovrw = window.confirm(question)
if (do_ovrw) {
document.modClient.submit( );
}
}
</script>
When the cancel button is clicked, the form submits anyway. Here is the related button code:
<input type="submit" name="SaveChanges"
onClick="javascript:confir mOverwrite ('Are you sure you want to overwrite this record?')"
value="Save Changes">
Why is the form still submitting?
<script type="text/javascript">
function confirmOverwrite(question)
var do_ovrw = window.confirm(question)
if (do_ovrw) {
document.modClient.submit(
}
}
</script>
When the cancel button is clicked, the form submits anyway. Here is the related button code:
<input type="submit" name="SaveChanges"
onClick="javascript:confir
value="Save Changes">
Why is the form still submitting?
change type="submit" to type="button"
or
onSubmit="return confirmOverwrite('Are you sure you want to overwrite this record?')"
like sad ho_alan, but move this to form tag
or
onSubmit="return confirmOverwrite('Are you sure you want to overwrite this record?')"
like sad ho_alan, but move this to form tag
oh yes!!! thx for pointing me out!
<form name=modClient onSubmit="return confirmOverwrite('Are you sure you want to overwrite this record?')" method=post action="yourdest.asp">
<input type="submit" name="SaveChanges" value="Save Changes">
</form>
<form name=modClient onSubmit="return confirmOverwrite('Are you sure you want to overwrite this record?')" method=post action="yourdest.asp">
<input type="submit" name="SaveChanges" value="Save Changes">
</form>
what a stupid careless mistake :-P....
that happens with me, too ;)
confim returns true if OK is clicked and false if CANCEL is clicked. There is no need for the function confirmOverwrite(), you can merely write this
<input type="submit" name="SaveChanges"
onSubmit="confirm('Are you sure you want to overwrite this record?')" value="Save Changes">
<input type="submit" name="SaveChanges"
onSubmit="confirm('Are you sure you want to overwrite this record?')" value="Save Changes">
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<script type="text/javascript">
function confirmOverwrite(question) {
if(confirm(question)){
return true;
}
else {
return false;
}
}
// -->
</script>
and then in the form tag use onsubmit
<form name="form1" action="" onsubmit="return confirmOverwrite('Are you sure you want to overwrite this record?');">
This is basically the same as GwynnforWeb's solution with the exception of i use a function
So Credits to her
function confirmOverwrite(question)
if(confirm(question)){
return true;
}
else {
return false;
}
}
// -->
</script>
and then in the form tag use onsubmit
<form name="form1" action="" onsubmit="return confirmOverwrite('Are you sure you want to overwrite this record?');">
This is basically the same as GwynnforWeb's solution with the exception of i use a function
So Credits to her
and i use onsubmit in the form tag
use onSubmit, rather than onClick here
<script type="text/javascript">
function confirmOverwrite(question)
var do_ovrw = window.confirm(question)
return do_overw;
}
</script>
<input type="submit" name="SaveChanges"
onSubmit="return confirmOverwrite('Are you sure you want to overwrite this record?')"
value="Save Changes">