Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- function formValidator(){
- var Two = document.getElementById('Two');//Category
- var Total = document.getElementById('Total');//Category
- var ExVAT = document.getElementById('ExVAT');//exVAT
- var AmtPaid = document.getElementById('AmtPaid');
- if(Multiply(Two, Total, "Total Amt must be double the first amount", "The first calculation is correct, click OK for 2nd calculation" )){
- if(isVAT(ExVAT, AmtPaid, "incorrect or validation not working correctly", "YES! Correct!")){
- return true;
- }
- }
- return false;
- }
- // if (val1 != "" && val2 != "")
- function Multiply(elem, elem2, helperMsg, correctMsg){
- if((elem2.value) == (elem.value*2)){
- alert(correctMsg);
- return true;
- }else{
- alert(helperMsg);
- elem.focus();
- return false;
- }
- }
- function isVAT(elem, elem2, helperMsg, correctMsg){
- if((elem2.value) == (elem.value*1.14)){
- alert(correctMsg);
- return true;
- }else{
- alert(helperMsg);
- elem.focus();
- return false;
- }
- }
- </script>
- <form action="alert('Correct!');" onsubmit="return formValidator()" >
- This one works:<br>
- <input type="text" id="Two" name="Two" value="2"> * 2 =
- <input type="text" id="Total" name="Total" value="4">
- <br><br>
- but this validation does not work:<br><br>
- eg. R100 ex VAT = R114incl VAT<br>
- Ex VAT: <input type="text" id="ExVAT" size = 7 name="ExVAT" value="10"><br>
- *1.14 = <br>
- AmtPaid: <input type="text" id="AmtPaid" name="AmtPaid" value="11.4">
- <br>
- <br>
- <input type="submit" value="Submit/Save" onsubmit='return formValidator()' style="width:300px;height:30px" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement