|
| |
|
|
aeryck
Posts: 22 Joined: 8/15/2005 From: 30 miles from Hell... (MI) Status: offline
|
Javascript question - 8/24/2005 8:49:44
Greetings all.. Not sure which forum I should've posted this in; the page in question is a database access page, but the part I need help with is a Javascript problem, and since I'm a beginner with Javascript, I figured that the Beginner's forum was the best place. :) On to my problem: I have an ASP form that posts data to a DB using the POST method. I have created a Javascript confirm function that pops up when the user clicks 'Submit'.. If the user clicks 'Cancel', it takes them back one page, erasing any changes to the form and taking them to the page before the update form.. Here's the code:
<script language="JavaScript" type="text/javascript">
function ConfirmSubmit() {
var cData;
cData = "\nMake: " + document.eqDetails.eqMake.value + "\nModel: " + document.eqDetails.eqModel.value + "\nSerial: " + document.eqDetails.eqSerial.value + "\nAccount: " + document.eqDetails.eqAccount.value + "\nDisposition: " + document.eqDetails.eqDisp.value;
DoIt = confirm("This action is immediate and irreversible. Please confirm to add the following:" + cData);
if (DoIt == false)
history.go(-1);
}
</script>
My question is: Is there a way to just halt the form from POST'ing, and leave the user on the form page so he or she can make any changes to the information and re-submit the form? Thanks in advance, //Aeryck
|
|
|
|
dpf
Posts: 7126 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: Javascript question - 8/24/2005 9:29:31
quote:
history.go(-1); that is the line that is sending them backa page - try removing that line
_____________________________
Dan
|
|
|
|
aeryck
Posts: 22 Joined: 8/15/2005 From: 30 miles from Hell... (MI) Status: offline
|
RE: Javascript question - 8/24/2005 10:11:23
quote:
that is the line that is sending them backa page - try removing that line I tried that already.. I also tried "history.go(0);" but no luck there either - Even if you click 'cancel', the form still posts.
|
|
|
|
dpf
Posts: 7126 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: Javascript question - 8/24/2005 10:40:24
what event handler is calling that script? onClick onSubmit ? when you remove the afroementioned line, replace it with return false;
_____________________________
Dan
|
|
|
|
aeryck
Posts: 22 Joined: 8/15/2005 From: 30 miles from Hell... (MI) Status: offline
|
RE: Javascript question - 8/24/2005 13:38:36
quote:
what event handler is calling that script? onClick onSubmit ? when you remove the afroementioned line, replace it with return false; Here's the code that calls the function:
<input TYPE="Submit" onclick=ConfirmSubmit()>
And here's the function based on what you mentioned:
<script language="JavaScript" type="text/javascript">
function ConfirmSubmit() {
var cData;
cData = "\nMake: " + document.eqDetails.eqMake.value + "\nModel: " + document.eqDetails.eqModel.value + "\nSerial: " + document.eqDetails.eqSerial.value + "\nAccount: " + document.eqDetails.eqAccount.value + "\nDisposition: " + document.eqDetails.eqDisp.value;
DoIt = confirm("This action is immediate and irreversible. Please confirm to add the following:" + cData);
if (DoIt == false)
return false;
}
</script>
Unfortunately, it still posts the form if 'Cancel' is clicked.
|
|
|
|
dpf
Posts: 7126 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: Javascript question - 8/24/2005 13:46:24
lets clean up the syntax first: function ConfirmSubmit() { var cData; cData = "\nMake: " + document.eqDetails.eqMake.value + "\nModel: " + document.eqDetails.eqModel.value + "\nSerial: " + document.eqDetails.eqSerial.value + "\nAccount: " + document.eqDetails.eqAccount.value + "\nDisposition: " + document.eqDetails.eqDisp.value; DoIt = confirm("This action is immediate and irreversible. Please confirm to add the following:" + cData); if (DoIt == false) { return false; } } </script> also, this may or may not help: <input TYPE="Submit" onclick=ConfirmSubmit(return, this)>
_____________________________
Dan
|
|
|
|
aeryck
Posts: 22 Joined: 8/15/2005 From: 30 miles from Hell... (MI) Status: offline
|
RE: Javascript question - 8/24/2005 15:45:18
quote:
lets clean up the syntax first: I wasn't sure if the braces are required; I know that in C, braces aren't required after an IF if there's a single statement in the "Then" part... I added them in, but it didn't change anything. quote:
also, this may or may not help: <input TYPE="Submit" onclick=ConfirmSubmit(return, this)> As soon as the page loads, I get a Syntax Error. The same applies if I try ConfirmSubmit(return). I don't get the syntax error if I use ConfirmSubmit(this), but the form still posts when a user clicks 'cancel'. If it would help, do you want me to post the entire page source so you can give it a quick proof? for all I know my mistake could be somewhere in a code bit I haven't posted. (The page is a bit lengthy; FP2003 lists it as 227 lines.) Thanks for your patience in helping me resolve this. :) //Aeryck
|
|
|
|
dpf
Posts: 7126 Joined: 11/12/2003 From: India-napolis Status: offline
|
RE: Javascript question - 8/24/2005 16:04:08
quote:
I know that in C, braces aren't required after an IF if there's a single statement in the "Then" part... I added them in, but it didn't change anything. you may be right about that... im gonna look at it some more
_____________________________
Dan
|
|
|
|
aeryck
Posts: 22 Joined: 8/15/2005 From: 30 miles from Hell... (MI) Status: offline
|
RE: Javascript question - 8/25/2005 16:33:54
I found the problem. :) Instead of:
<input type=submit onclick=ConfirmSubmit()>
I used:
<input type=submit onclick="return ConfirmSubmit()">
That was my problem.. After I added the 'return' statement, it works great - clicking cancel does not post the form. I appreciate your time and suggestions. :) //Aeryck
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|