Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

After validating a form then show data in new window

Status
Not open for further replies.

gronsky

Technical User
Feb 8, 2002
36
0
0
US
My dele...dilemm...problem is this, when the html below is run, it will validate the forms's inputs. What I would then like to do after the validation is to open a formatted html doc in a popup window that shows the form's data. Could this be done with document.write? Also could all of this be done with a single button?

Thanks

===============
Code:
<html><head><title></title>
  <SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
function display() {
  DispWin = window.open('','NewWin', 'toolbar=no,status=no,width=300,height=500')
  message = &quot;<ul><li><b>NAME: </b>&quot; + document.myform.fname.value + &quot;</ul>&quot;;
  //add more later
  DispWin.document.write(message);
}  

// Preload images
var empty = new Image(); empty.src = &quot;Pix/fieldempty.gif&quot;;
var email = new Image(); email.src = &quot;Pix/emailerror.gif&quot;;
var zipcd = new Image(); zipcd.src = &quot;Pix/ziperror.gif&quot;;
var phone = new Image(); phone.src = &quot;Pix/phoneerror.gif&quot;;

var haveerrors = 0;
function showImage(imagename, imageurl, errors) {
document[imagename].src = imageurl;
if (!haveerrors && errors) haveerrors = errors;
}

function validateForm(f) {
haveerrors = 0;
(f.fname.value.length < 1) // validate first name length
? showImage(&quot;firstnameerror&quot;, &quot;Pix/fieldempty.gif&quot;, true)   // no semi-colon after this line!
: showImage(&quot;firstnameerror&quot;, &quot;Pix/blankimage.gif&quot;, false); // true = errors, false = no errors


return (!haveerrors);

}
//  End -->
</script>
</head>
<body>
<center>
<form method=&quot;get&quot;  ACTION=&quot;gpl1.html&quot; name=&quot;myform&quot; onSubmit=&quot;return validateForm(this)&quot;  >
<table border=0 cellspacing=0 celpadding=0>    
<tr>
<td colspan=2>Enter your information:<br>
<sup>(<font color=&quot;#ff0000&quot;>*</font> denotes required field).</sup></td>
</tr>
<tr>
<td><p align=right>
First Name:</td>
<td>
<input type=text name=&quot;fname&quot; size=25 maxlength=50><font color=&quot;#ff0000&quot;>*</font><br>
<img name=firstnameerror src=&quot;Pix/blankimage.gif&quot; width=350 height=10 border=0></td>
</tr>
<tr>
<td><p align=center>
</td>
<td><p align=right>
<input type=submit value=&quot;Submit Form&quot;>
</td>
</tr>
</table>
</form>
</center>
</center><p>
</body>
</html>

 
function validateForm(f) {
haveerrors = 0;
(f.fname.value.length < 1) // validate first name length
? showImage(&quot;firstnameerror&quot;, &quot;Pix/fieldempty.gif&quot;, true) // no semi-colon after this line!
: showImage(&quot;firstnameerror&quot;, &quot;Pix/blankimage.gif&quot;, false); // true = errors, false = no errors


if (!haveerrors){
myWindow = window.open (&quot;&quot;,&quot;myWin&quot;)
myWindow.document.write(&quot;First Name = '&quot; + f.fname.value + &quot;'&quot;)
}


return (!haveerrors);

}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
And yes, this can be automated so that it loops thought the input boxes in the form w/o having to hardcode the whole thing...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Hey mwolf00,

Yes that's it! Great! Thanks!!
Now for the big question, since I'm new to javascript, how would you do the looping????
 
if (!haveerrors){
myWindow = window.open (&quot;&quot;,&quot;myWin&quot;)
for (x=0; x<f.elements.length; x++){
myWindow.document.writeln(f.elements[x].name = '&quot; + f.elements[x].value + &quot;'&quot;)
}

}

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top