Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- var totalcost = 0;
- var numanimals = 0;
- function checkAnimals()
- {
- var animalselector = document.getElementById("animals");
- // <option value = "1">Tiger $2000</option>
- // <option value = "2">Elephant $1900</option>
- // <option value = "3">Chimpanzee $1800</option>
- // <option value = "4">Warthog $1050</option>
- // <option value = "5">Lemur $180</option>
- numanimals = 0;
- totalcost = 0;
- if (animalselector[0].selected)
- {
- numanimals++;
- totalcost+=2000;
- }
- if (animalselector[1].selected)
- {
- numanimals++;
- totalcost+=1900;
- }
- if (animalselector[2].selected)
- {
- numanimals++;
- totalcost+=1800;
- }
- if (animalselector[3].selected)
- {
- numanimals++;
- totalcost+=1050;
- }
- if (animalselector[4].selected)
- {
- numanimals++;
- totalcost+=190;
- }
- return numanimals>0;
- }
- function checkCard()
- {
- var cardinput = document.getElementById("cardnum");
- var cardnumber = cardinput.value;
- var numdigits = 0;
- var len = cardnumber.length;
- for(var i = 0; i<len; i++)
- {
- var ch = cardnumber.charAt(i);
- if ((ch >='0') && (ch <= '9'))
- {
- numdigits++;
- }
- }
- return numdigits == 16;
- }
- function checkCardName()
- {
- var cardnumber = document.getElementById("cardnum");
- var cardinput = document.getElementById("cardname");
- if (cardinput[0].selected)
- {
- if (cardnumber.value.charAt(0) == '4')
- {
- return true;
- }
- else
- return false;
- }
- if (cardinput[1].selected)
- {
- if (cardnumber.value.charAt(0) == '5')
- {
- return true;
- }
- else
- return false;
- }
- else
- return false;
- }
- function confirmSubmit()
- {
- if (!checkAnimals())
- {
- alert("You didn't select an animal to sponsor");
- return false;
- }
- else if (!checkCard())
- {
- alert("Your credit card details are invalid");
- return false;
- }
- else if (!checkCardName())
- {
- alert("Your credit card details are invalid (try 4 or 5 as the first digit)");
- return false;
- }
- // alert("nurrrrrrrrr");
- else
- {
- msg = "Thankyou for offering to sponsor ";
- if (numanimals == 1) msg = msg + "one of our zoo's residents.";
- else msg = msg + numanimals + " of our zoo's residents.";
- msg = msg + "The cost of sponsorship is $" + totalcost;
- msg = msg + ". Confirm order.";
- return confirm(msg);
- }
- }
Add Comment
Please, Sign In to add comment