spinsane
01-27-2006, 08:23 PM
Hello,
I am currently working on a project that formats variables from a form and writes them to a new page to be printed, The form also has an online submit routine so the easy route is already being used. I am using a button with javascript to open a new window and write the values of each form field to the new window in a printer friendly format (Darn Text Areas).
I thought i had it but my script is not working, If anyone could review my code to see where I screwed up it would be greatly appreciated.
<html>
<head>
<title>Damn Form that won't work</title>
<script type="text/javascript">
function printField() {
var name = document.contactForm.q[1].value;
var email = document.contactForm.email.value;
var phone = document.contactForm.q[2].value;
var st1 = document.contactForm.q[3].value;
var st2 = document.contactForm.q[4].value;
var city = document.contactForm.q[5].value;
var state = document.contactForm.q[6].value;
var zip = document.contactForm.q[7].value;
var year = document.contactForm.q[8].value;
var make = document.contactForm.q[9].value;
var model = document.contactForm.q[10].value;
var opts = document.contactForm.q[11].value;
var story = document.contactForm.q[12].value;
var regExp=/\n/gi;
s = s.replace(regExp,'<br>');
pWin = window.open('','pWin','location=no, menubar=yes, toolbar=no');
pWin.document.open();
pWin.document.write('<html><head></head><body>');
pWin.document.write('Name: ' + name + '<br>');
pWin.document.write('E-Mail: ' + email + '<br>');
pWin.document.write('Phone: ' + phone + '<br>');
pWin.document.write('Street Address: <table><tr><td>' + st1 + '</td></tr><tr><td>' + st2 + '</td></tr><tr><td>' + city + ', ' + state + ' ' + zip + '<br><br>');
pWin.document.write('<h3><div align="center">My Vehicle</div></h3><br>');
pWin.document.write('Year: ' + year + '<br>');
pWin.document.write('Make: ' + make + '<br>');
pWin.document.write('Model: ' + model + '<br>');
pWin.document.write('Options: ' + opts + '<br><br>');
pWin.document.write('<h3><div align="center">Why my vehicle should be the next CoverCar</div></h3><br>');
pWin.document.write('<br>' + story + '<br>');
pWin.document.write('</body></html>');
pWin.print();
pWin.document.close();
pWin.close();
}
</script>
</head>
<body>
<form name="contactForm" method="post" action="http://www.mycontactform.com/sendform/sendform.php" onreset="return confirm('Really reset all form fields?')">
<input name="user" type="hidden" id="user" value="quanta">
<input name="formid" type="hidden" id="formid" value="38618">
<input name="subject" type="hidden" id="subject" value="Entry Photo">
Name: <input type="text" name="q[1]"><br>
Email: <input type="text" name="email"><br>
Address: <textarea name="q[2]"></textarea>
<!-- Form shortened but you get the Idea -->
<button type="submit">Submit your entry online</button><br><br>
<button onclick="printField()">Submit your Entry via SnailMail</button>
Any help would be appreciated, I've been looking at this code too long and can't figure it out.
Actual page online at: http://www.quantaproducts.com/contest/contestentries.asp
I am currently working on a project that formats variables from a form and writes them to a new page to be printed, The form also has an online submit routine so the easy route is already being used. I am using a button with javascript to open a new window and write the values of each form field to the new window in a printer friendly format (Darn Text Areas).
I thought i had it but my script is not working, If anyone could review my code to see where I screwed up it would be greatly appreciated.
<html>
<head>
<title>Damn Form that won't work</title>
<script type="text/javascript">
function printField() {
var name = document.contactForm.q[1].value;
var email = document.contactForm.email.value;
var phone = document.contactForm.q[2].value;
var st1 = document.contactForm.q[3].value;
var st2 = document.contactForm.q[4].value;
var city = document.contactForm.q[5].value;
var state = document.contactForm.q[6].value;
var zip = document.contactForm.q[7].value;
var year = document.contactForm.q[8].value;
var make = document.contactForm.q[9].value;
var model = document.contactForm.q[10].value;
var opts = document.contactForm.q[11].value;
var story = document.contactForm.q[12].value;
var regExp=/\n/gi;
s = s.replace(regExp,'<br>');
pWin = window.open('','pWin','location=no, menubar=yes, toolbar=no');
pWin.document.open();
pWin.document.write('<html><head></head><body>');
pWin.document.write('Name: ' + name + '<br>');
pWin.document.write('E-Mail: ' + email + '<br>');
pWin.document.write('Phone: ' + phone + '<br>');
pWin.document.write('Street Address: <table><tr><td>' + st1 + '</td></tr><tr><td>' + st2 + '</td></tr><tr><td>' + city + ', ' + state + ' ' + zip + '<br><br>');
pWin.document.write('<h3><div align="center">My Vehicle</div></h3><br>');
pWin.document.write('Year: ' + year + '<br>');
pWin.document.write('Make: ' + make + '<br>');
pWin.document.write('Model: ' + model + '<br>');
pWin.document.write('Options: ' + opts + '<br><br>');
pWin.document.write('<h3><div align="center">Why my vehicle should be the next CoverCar</div></h3><br>');
pWin.document.write('<br>' + story + '<br>');
pWin.document.write('</body></html>');
pWin.print();
pWin.document.close();
pWin.close();
}
</script>
</head>
<body>
<form name="contactForm" method="post" action="http://www.mycontactform.com/sendform/sendform.php" onreset="return confirm('Really reset all form fields?')">
<input name="user" type="hidden" id="user" value="quanta">
<input name="formid" type="hidden" id="formid" value="38618">
<input name="subject" type="hidden" id="subject" value="Entry Photo">
Name: <input type="text" name="q[1]"><br>
Email: <input type="text" name="email"><br>
Address: <textarea name="q[2]"></textarea>
<!-- Form shortened but you get the Idea -->
<button type="submit">Submit your entry online</button><br><br>
<button onclick="printField()">Submit your Entry via SnailMail</button>
Any help would be appreciated, I've been looking at this code too long and can't figure it out.
Actual page online at: http://www.quantaproducts.com/contest/contestentries.asp