earwig75
asked on
Display Javascript Confirmation box on form submit with form contents
I'd like to pop open a javascript alert box and show the details of a form before submitting.
Below is what I have so far for the JavaScript. Could someone assist? Thank you.
Below is what I have so far for the JavaScript. Could someone assist? Thank you.
<form name="myForm" onsubmit="confirm()">
<input type="text" id="theNumber" name="theNumber" />
<input type="text" id="theName" name="theName" />
<script language="javascript">
function Confirm(){
var theNumber = document.getElementById("theNumber").value;
var theName = document.getElementById("theName").value;
var r=confirm("Are you sure you want to submit these details?");
if (r==true)
{
//show something like the below here
The Number: theNumber here
The Name: theName here
}
else
{
alert("You pressed Cancel!");
}
</script>
ASKER
I apologize, I need the form details to come before the if r==true... I'd like them to see the form details before clicking Ok.
ASKER
Also, when I pressed cancel it submitted the form instead of returning false.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Open in new window
NOTE: Javascript is case sensitive, so you need onsubmit="Confirm()" -- with capital "C"