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!

IF statements within document.write

Status
Not open for further replies.

gargs

Technical User
Apr 3, 2001
14
NZ
Why does this code not work??

nw.document.writeln (&quot;<tr><td width=50><td width=130 class=lbl><b>Company Name:</b></lbl><td>&quot;) & document.frmorder.txtco_name.value & (&quot;</td></td></td></tr>&quot;)

nw.document.writeln (&quot;<tr><td width=50><td width=130 class=lbl><b>Postal Address:</b></lbl><td>&quot;) & document.frmorder.txtaddr.value & (&quot;</td></td></td></tr>&quot;)

nw.document.writeln (if document.frmorder.txtsuburb.value <> &quot;&quot; then nw.document.writeln (&quot;<tr><td width=50><td width=130 class=lbl><b>Suburb:</b></lbl><td>&quot;) & document.frmorder.txtsuburb.value & (&quot;</td></td></td></tr>&quot;)

The first two lines are required fields in the form so will always be written to the invoice (and they work) The third line is writing a non-required field and I get a syntax error with the if statement.

So if &quot;txtsuburb&quot; is not blank then write it, else leave it out. Can this be done?

Thanks in advance

Grattan
 
gargs,

Just take the if loop out of the document.writeln statement:

if document.frmorder.txtsuburb.value <> &quot;&quot; then
nw.document.writeln (&quot;<tr><td width=50><td width=130 class=lbl><b>Suburb:</b></lbl><td>&quot;) & document.frmorder.txtsuburb.value & (&quot;</td></td></td></tr>&quot;)
end if
Mise Le Meas,

Mighty :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top