gallipro
asked on
How do I enable a print page button after successful form validation?
I am creating a form for a customer that is meant to be printed and not submitted. The requirement is after all the required fields are filled in and validated but a print button, the form should automatically prompt to print the window. Here is a link
http://www.chepcanada.ca/welcome/application.html
The print button should be disabled until the form validation returns true, or there should be one button and after successful validation, the page should print.
http://www.chepcanada.ca/welcome/application.html
The print button should be disabled until the form validation returns true, or there should be one button and after successful validation, the page should print.
Assuming your validation is in place all you have to do is call "window.print();" where the validation returns true and a print dialog will come up.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try something like this??
<html>
<head>
<title>Untitled</title>
<script language="JavaScript">
function validatethenprint()
{
if (document.getElementById("field1").value.length<1) {
alert('Please specify Field 1.');
document.getElementById("field1").focus();
return false;}
if (document.getElementById("field2").value.length<1) {
alert('Please specify Field 2.');
document.getElementById("field2").focus();
return false;}
if (document.getElementById("field3").value.length<1) {
alert('Please specify Field 3.');
document.getElementById("field3").focus();
return false;}
window.print();
}
</script>
</head>
<body>
<form name="myform" action="#" method="post" onsubmit="validatethenprint();return false;">
<input type="Text" name="field1" id="field1"><br />
<input type="Text" name="field2" id="field2"><br />
<input type="Text" name="field3" id="field3"><br />
<input type="Submit" value="Validate and Print">
</form>
</body>
</html>