Dman87
01-04-2007, 10:50 AM
Hello all dident know if this was the wright place to post this if its not just move it. Im having some problem with the validation function (yes im new to javascript) my page wont display what i want it to. and also my clear all button dosent work now eather. and i think the problem is the cost bit of the code i must be doing it wrong, when the user selects and option eg all inclusive and he/she is over 60 they get 50% off, thats how its suppost to work.
function validate code
code:
<html>
<head>
<script type = "text/javascript">
function blanks()
{form1.reset()}
function validate()
{
title = form1.s1.options[form1.s1.selectedIndex].text
forename = form1.forename.value
surname = form1.surname.value
street = form1.street.value
town = form1.town.value
postcode = form1.postcode.value
email = form1.email.value
age = form1.age.value
type = form1.s2.options[form1.s2.selectedIndex].text
if ((age=="") || (forename=="") || (surname=="") || (title=="Pick") || (street=="") || (town=="") || (postcode=="") || (email=="") || (type=="pick"))
{
alert("Missing Details")
}
else
{
if (parseInt(age)<18)
{
alert("You must be over 18 to register")
}
else
{
cost = 0
"All inclusive" = 500.00
"Waterskiing only" = 200.00
"Canoeing only" = 100.00
"Fishing only" = 300.00
ages = parseInt(age)
if (ages >= 60)
{
cost = "All inclusive" - ("All inclusive"*0.50)
cost = "Waterskiing only" - ("Waterskiing only"*0.50)
cost = "Canoeing only" - ("Canoeing only"*0.50)
cost = "Fishing only" - ("Fishing only"*0.50)
}
if ((ages >= 45) && (ages < 60))
{
cost = "All inclusive" - ("All inclusive"*0.25)
cost = "Waterskiing only" - ("Waterskiing only"*0.25)
cost = "Canoeing only" - ("Canoeing only"*0.25)
cost = "Fishing only" - ("Fishing only"*0.25)
}
if ((ages >=18) && (ages<40))
{
cost = "All inclusive"
cost = "Waterskiing only"
cost = "Canoeing only"
cost = "Fishing only"
}
alert(forename.substring(0,1).toUpperCase()+". "+surname+"\n"+type.toUpperCase()+"\nCost = £"+cost.toFixed(2))
}
}
}
function getName()
{
var Name = new Array(3)
var Email = new Array(3)
for (i=0;i<Name.length;i++)
{
Name[i] = prompt("Please enter Name ","")
Email[i] = prompt("Please enter Email ","")
}
document.write("The following people will recieve a message: "+"<br>")
for (i=0;i<Name.length;i++)
{
document.write("Name : "+Name[i])
document.write(" Email : "+Email[i]+"<br>")
}
}
code:
And the option
code:
<p>
Membership Type
<select name="select" id="s2">
<option value="Pick type">Pick</option>
<option value="£500.00">All inclusive</option>
<option value="£200.00">Waterskiing only</option>
<option value="£100.00">Canoeing only</option>
<option value="£300.00">Fishing only</option>
</select>
</p>
code:
as i say im new to javascript and new to forums, be nice, and if you can help that would be a plus.
function validate code
code:
<html>
<head>
<script type = "text/javascript">
function blanks()
{form1.reset()}
function validate()
{
title = form1.s1.options[form1.s1.selectedIndex].text
forename = form1.forename.value
surname = form1.surname.value
street = form1.street.value
town = form1.town.value
postcode = form1.postcode.value
email = form1.email.value
age = form1.age.value
type = form1.s2.options[form1.s2.selectedIndex].text
if ((age=="") || (forename=="") || (surname=="") || (title=="Pick") || (street=="") || (town=="") || (postcode=="") || (email=="") || (type=="pick"))
{
alert("Missing Details")
}
else
{
if (parseInt(age)<18)
{
alert("You must be over 18 to register")
}
else
{
cost = 0
"All inclusive" = 500.00
"Waterskiing only" = 200.00
"Canoeing only" = 100.00
"Fishing only" = 300.00
ages = parseInt(age)
if (ages >= 60)
{
cost = "All inclusive" - ("All inclusive"*0.50)
cost = "Waterskiing only" - ("Waterskiing only"*0.50)
cost = "Canoeing only" - ("Canoeing only"*0.50)
cost = "Fishing only" - ("Fishing only"*0.50)
}
if ((ages >= 45) && (ages < 60))
{
cost = "All inclusive" - ("All inclusive"*0.25)
cost = "Waterskiing only" - ("Waterskiing only"*0.25)
cost = "Canoeing only" - ("Canoeing only"*0.25)
cost = "Fishing only" - ("Fishing only"*0.25)
}
if ((ages >=18) && (ages<40))
{
cost = "All inclusive"
cost = "Waterskiing only"
cost = "Canoeing only"
cost = "Fishing only"
}
alert(forename.substring(0,1).toUpperCase()+". "+surname+"\n"+type.toUpperCase()+"\nCost = £"+cost.toFixed(2))
}
}
}
function getName()
{
var Name = new Array(3)
var Email = new Array(3)
for (i=0;i<Name.length;i++)
{
Name[i] = prompt("Please enter Name ","")
Email[i] = prompt("Please enter Email ","")
}
document.write("The following people will recieve a message: "+"<br>")
for (i=0;i<Name.length;i++)
{
document.write("Name : "+Name[i])
document.write(" Email : "+Email[i]+"<br>")
}
}
code:
And the option
code:
<p>
Membership Type
<select name="select" id="s2">
<option value="Pick type">Pick</option>
<option value="£500.00">All inclusive</option>
<option value="£200.00">Waterskiing only</option>
<option value="£100.00">Canoeing only</option>
<option value="£300.00">Fishing only</option>
</select>
</p>
code:
as i say im new to javascript and new to forums, be nice, and if you can help that would be a plus.