Wednesday, 11 September 2013

Making HTML onClick events conditional

Making HTML onClick events conditional

I've asked this question before, and got it to be functional in ie7. Since
then, we upgraded to IE 8 and I can not find a way to make it work. I have
a form that is manually filled out by the user, and when they click copy,
the form is concatenated into a single text box with formatting applied. I
need the formatting to be conditional, so if certain parts of the form are
not entered or left blank, they do not leave an empty line break in the
formatting. Example Form:
<body>
<form name="data_entry" id="frm1"
<tr>
<td>Name of Person:</td>
<td><textarea name="name" rows="2" cols="30" id="name"></textarea></td>
</tr><br>
<tr>
<td>Type of Service:</td>
<td><select name="drop1" id="txt_drop1">
<option value="">None</option>
<option value="Type of Service: Minimal">Minimal</option>
<option value="Type of Service: Normal">Normal</option>
<option value="Type of Service: Full">Full</option>
<option value="Type of Service: Premium">Premium</option>
</select></td>
</tr><br>
<tr>
<td>Dollar Amount:</td>
<td><textarea name="amount" rows="1" cols="30"
id="txt_info2"></textarea></td>
</tr><br>
<tr>
<td><textarea name="bigtextbox" rows="5" cols="30"
id="txt_info2"></textarea></td>
</tr>
</form>
</body>
<input type="button" style="font-weight:bold;" name="clipboard_copy"
value="Copy" onClick="document.data_entry.bigtextbox.value = 'Name:&nbsp;'
+ document.data_entry.name.value + '\n' + document.data_entry.drop1.value
+ '\n' + 'Amount: $' + document.data_entry.amount.value">
</body>
The result Im looking to acheive is to have it look like so if the "type
of service" value is empty:

Name: John Smith
Amount:$123

Rather than:

Name: John Smith

Amount:$123

It would also need to work for cases where they leave any other field blank.
Thanks in advance, and sorry for the repeat question!

No comments:

Post a Comment