Newbie has problems with functions and multiline calculations.
Hi everybody.
I am having a bit of difficulty here. (Essentially because I am not very good at coding - as you will see by the state of my it below.)
My form1 clear button doesn't seem to work (clear all feids), neither does my validate funtion (it should check that contents have been entered into a field), and my little discount calculation should apply to each of the four options in my combo-box titled SLCT_member.
Can anyone help. The buttons not working is probably really simple, but I can't see what it is.
I'm working with notepad, so nothing is highlighted for me.
I appreciate any help with this? I've been fiddling with it for ages but I have a feeling that I'm just making it worse.
I am having a bit of difficulty here. (Essentially because I am not very good at coding - as you will see by the state of my it below.)
My form1 clear button doesn't seem to work (clear all feids), neither does my validate funtion (it should check that contents have been entered into a field), and my little discount calculation should apply to each of the four options in my combo-box titled SLCT_member.
Can anyone help. The buttons not working is probably really simple, but I can't see what it is.
I'm working with notepad, so nothing is highlighted for me.
<html>
<head>
<script type ="text/javascript">
function blanks()
{
form1.reset()
}
function blanks2()
{
form2.reset()
}
function validate()
{
title = form1.RAD_title.value
firstname = form1.TXT_forename.value
secondname = form1.TXT_surname.value
houseno = form1.TXT_houseno.value
street = form1.TXT_street.value
town = form1.TXT_town.value
postcode1 = form1.TXT_postcode1.value
postcode2 = form1.TXT_postcode2.value
email1 = form2.TXT_email1.value
email2 = form2.TXT_email2.value
email3 = form2.TXT_email3.value
membership = form1.SLCT_member.options[form1.SLCT_mem ber.selectedIndex].txt
age = form1.TXT_age.value
if ((title==""||(firstname=="")||(secondnam e=="")||(houseno=="")||(street=="")||(to wn=="")||(postcode1=="")||(postcode2=="" )||(email1=="")||(email2=="")||(email3== "")||(membership=="Please select one option")||(age==""))
{
alert("Please ensure you have filled in all the details before submitting the form")
}
else
{
if (parseInt(TXT_age)<18)
{alert("Sorry, You must be 18 years of age or older to register")
}
else
{
cost = 0
allinc = 500.00
wtrskii = 200.00
canoe = 100.00
fishing = 300.00
custage = parseInt(TXT_age)
if (custage >=60)
{
cost =allinc-(allinc*0.20)
}
if ((custage >=40)&&(ages<60))
{
cost =allinc-(allinc*0.10)
}
if ((custage >=18)&&(ages<40))
{
cost = allinc
}
alert(title+" "+firstname+" "+secondname+" "+houseno+" "+street+" "+town+" "+postcode1+" "+postcode2+" "+email1+" "+email2+" "+email3+" "+membership+" "+age+" "cost=£"+cost.toFixed(2))
}
}
}
</script>
<title>Loch Oich Water Centre application</title>
</head>
<body>
<form name="form1">
<p><b>Title:</b>Mr.<input type="radio" value="V1" name="RAD_title">Mrs.<input type="radio" value="V2" name="RAD_title">Ms.<input type="radio" value="V3" name="RAD_title">Dr.<input type="radio" value="V4" name="RAD_title">Other
<font size="1">(Please specify) </font> <input type="text" name="TXT_title1" size="9"></p>
<p><b>Forename:</b><input type="text" name="TXT_forename" size="20">
<b>Surname: </b> <input type="text" name="TXT_surname" size="22"></p>
<p><b>House No.</b> <input type="text" name="TXT_houseno" size="5"> <b>Street:
</b>
<input type="text" name="TXT_street" size="40"></p>
<p><b>Town: </b><input type="text" name="TXT_town" size="20"> <b>Post-code:</b><input type="text" name="TXT_postcode1" size="5"><input type="text" name="TXT_postcode2" size="4"></p>
<p><b>email: <input type="text" name="TXT_email1" size="14">@<input type="text" name="TXT_email2" size="20">.<input type="text" name="TXT_email3" size="10"></b></p>
<p>
<p><b>Age:</b><input type="text" name="TXT_age" id="TXT_age" size="3">
</p>
<table width="52%" border="3" cellspacing="1" cellpadding="1">
<tr>
<td width="18%">TYPE</td>
<td width="26%">DESCRIPTION</td>
<td width="56%">COST</td>
</tr>
<tr>
<td>1</td>
<td>All inclusive</td>
<td>£500.00</td>
</tr>
<tr>
<td>2</td>
<td>Waterskiing only</td>
<td>£200.00</td>
</tr>
<tr>
<td>3</td>
<td>Conoeing</td>
<td>£100.00</td>
</tr>
<tr>
<td>4</td>
<td>Fishing Only</td>
<td>£300.00</td>
</tr>
</table>
<p><strong>Membership</strong><strong> Type:</strong></p>
<p><strong> <select name="SLCT_member" size="4">
<option value="selectanoption">Please select one option</option>
<option value="allinc">All inclusive</option>
<option value="wtrskii">Water Skiing only</option>
<option value="canoe">Canoeing</option>
<option value="fishing">Fishing Only</option>
</select>
</strong></p>
<p><strong>Disability</strong><font size="1">(tick if applicable)</font><strong>:
<input type="checkbox" name="CHKBX_disability" value="checkbox">
</strong></p>
<p>
<input type="button" name="BTN_submit1" value="send" onclick="validate()">
<input type="button" name="BTN_clear1" value="clear" onclick="blanks()">
</p>
</form>
<hr>
<form name="form2" method="post" action="">
<p><strong>Fill in the form below with friends email addresses to recommend:</strong></p>
<p><b>
<input type="text" name="TXT_friendemail1" size="50">
</b></p>
<p><b>
<input type="text" name="TXT_friendemail2" size="50">
</b></p>
<p><b>
<input type="text" name="TXT_friendemail3" size="50">
</b></p>
<p>
<input type="button" name="BTN_submit2" value="send">
<input type="button" name="BTN_clear2" value="clear" onclick="blanks2()">
</p>
</form>
</body>
</html>
I appreciate any help with this? I've been fiddling with it for ages but I have a feeling that I'm just making it worse.
