0

I have a textbox with id=DiscountCode. Someone must enter the correct discount code in order for the form to submit. If it does not match, then there will be an alert and form will not submit. Right now, using this code, it only accepts exact entry and is case sensitive. Can someone help me to make the answer someone types in case insensitive? Thank you.

<script>
  function validateForm(form) {  
   if (document.getElementById("DiscountCode").value != "RegStudent") {
   alert("Sorry, but you have entered the wrong discount code"); 
   return false;  
   }
  }
</script>
dr1054
  • 89
  • 1
  • 4
  • 10
  • Why don't you call `toLowerCase()` on the discount code they've entered, and use a lowercase `"regstudent"` string...? – Geoff James Nov 30 '16 at 20:30
  • if (document.getElementById("DiscountCode").value.toLowerCase() != "regstudent" – Kyle Nov 30 '16 at 20:31
  • 1
    And also you should not store your "secret" code in your html/js file as the user can just inspect the source code and enter the correct code. This should all be handled by your server – DZDomi Nov 30 '16 at 20:32
  • Thanks Kyle, works perfectly. – dr1054 Nov 30 '16 at 20:34

0 Answers0