Advertisement
misterFanta

FormValidation need help V2

Jul 30th, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2. function formValidator(){
  3.     var Two = document.getElementById('Two');//Category
  4.     var Total = document.getElementById('Total');//Category
  5.     var ExVAT = document.getElementById('ExVAT');//exVAT
  6.     var AmtPaid = document.getElementById('AmtPaid');
  7.  
  8.     if(Multiply(Two, Total, "Total Amt must be double the first amount", "The first calculation is correct, click OK for 2nd calculation"  )){
  9.         if(isVAT(ExVAT, AmtPaid,  "incorrect or validation not working correctly", "YES! Correct!")){
  10.                 return true;
  11.         }
  12.     }
  13. return false;
  14. }
  15.  // if (val1 != "" && val2 != "")
  16.  
  17. function Multiply(elem, elem2, helperMsg, correctMsg){
  18.     if((elem2.value) == (elem.value*2)){
  19.         alert(correctMsg);
  20.         return true;
  21.     }else{
  22.         alert(helperMsg);
  23.         elem.focus();
  24.         return false;
  25.     }
  26. }
  27. function isVAT(elem, elem2, helperMsg, correctMsg){
  28.     if((elem2.value) == (elem.value*1.14)){
  29.         alert(correctMsg);
  30.         return true;
  31.  
  32.     }else{
  33.         alert(helperMsg);
  34.         elem.focus();
  35.         return false;
  36.     }
  37. }
  38.  
  39.  
  40. </script>
  41. <form  action="alert('Correct!');"  onsubmit="return formValidator()" >
  42. This one works:<br>
  43. <input type="text" id="Two" name="Two" value="2"> *  2 =
  44. <input type="text" id="Total" name="Total" value="4">
  45. <br><br>
  46.  
  47. but this validation does not work:<br><br>
  48.  
  49.  
  50. eg. R100 ex VAT = R114incl VAT<br>
  51.  
  52. Ex VAT: <input type="text" id="ExVAT" size = 7 name="ExVAT" value="10"><br>
  53. *1.14 = <br>
  54. AmtPaid: <input type="text" id="AmtPaid" name="AmtPaid" value="11.4">
  55. <br>
  56. <br>
  57.  
  58. <input type="submit" value="Submit/Save"  onsubmit='return formValidator()'  style="width:300px;height:30px" />
  59. </form>
  60. </body>
  61. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement