View Full Version : ASP Reload w/o ReSendin Form Vars
Roost3r
05-08-2003, 04:14 AM
Hi
I have a asp page which has a form with a delete button... it posts to the same page... in the code where it checks to see if the delete button was pressed im creating javascript to do a confirm popup...
var confimation = confirm("Are you Sure?");
if(confirmation == false) {
location.href = location.href;
}
everything i tried wouldnt prevent the record from being deleted... the sql query to delete this record is like 1 -2 lines after the javascript there
any ideas?
ive also tried
location.href = history.go(0);
location.href = hostory.go(-1);
TIA
arnyinc
05-08-2003, 01:30 PM
Use the onsubmit event to validate when you submit the form. If you aren't use a "real" submit button (i.e. type="submit" vs. type="button") there needs to be a couple changes.
<html>
<head>
<script language="javascript">
function validate(){
if (confirm('Are you sure you want to delete this?'))
return true;
else
return false;
}
</script>
</head>
<body>
<form onsubmit="return validate();" action="buh.htm" method="get">
<input type="hidden" name="exec_delete" value="yes">
<input type="submit">
</form>
<%
if request.querystring("exec_delete")="yes" then
'put your code to delete the entry here
end if
%>
</body>
</html>
Roost3r
05-08-2003, 05:52 PM
I dont see how that would work because the hidden value your chacking to execute the form remains static as true/yes
arnyinc
05-08-2003, 06:22 PM
When the page first loads, the form hasn't been submitted yet, so the variable will be equal to "". Once you submit the form, then the value of exec_delete will be set equal to "yes".
Try it out with this code (same thing, but I change the action and put text on the submit button). Create a file called whatever.asp
<html>
<head>
<script language="javascript">
function validate(){
if (confirm('Are you sure you want to delete this?'))
return true;
else
return false;
}
</script>
</head>
<body>
<form onsubmit="return validate();" action="whatever.asp" method="get">
<input type="hidden" name="exec_delete" value="yes">
<input type="submit" value="Click here to delete">
</form>
<%
if request.querystring("exec_delete")="yes" then
'put your code to delete the entry here instead of this print command
response.write "DELETED!"
end if
%>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.