I have this two images:
image1:
image2:
My problem here is that every time i click the submit button, the error messages just adds up to the previous set of error messages. how can I prevent this from happening? What I want to do is that every time I click the submit button, the javascript would only show the current set of error messages... deleting or disregarding the previous one...
this is my code - TextValidation.js (a seperate javascript file):
Code://Text Validation for Product Details var numericExpression = /^[0-9]+$/; var error = ""; function validate_Product() { validate_ProductName(); validate_ProductPrice(); validate_StockUnit(); validate_reorderPt(); validate_Weight(); validate_Tax(); validate_Description(); if (error != "") { alert(error); return false; } } function validate_ProductName() { // debugger; var name = document.getElementById('ctl00$ContentPlaceHolder1$txtProductName').value; if(name == '') { error = error + '\nProduct Name: Please enter a Product Name'; } else if (name.length >50) { error = error + '\nProduct Name: You\'re only allowed to enter up to 50 characters.'; } } function validate_ProductPrice() { var price = document.getElementById('ctl00$ContentPlaceHolder1$txtPrice').value; if (price == '') { error = error + '\nProduct Price: Please enter the product price.'; } else if (price.match(!numericExpression)) { error = error + '\nProduct Price: Please enter numeric values only.'; } } function validate_StockUnit() { var stockUnit = document.getElementById('ctl00$ContentPlaceHolder1$txtUnitId').value; if (stockUnit == '') { error = error + '\nStock Unit: Please enter a Stock Unit.'; } else if (stockUnit.match(!numericExpression)) { error = error + '\nStock Unit: Please enter numeric values only.'; } } function validate_reorderPt() { var reorderPt = document.getElementById('ctl00$ContentPlaceHolder1$txtReorderPt').value; if (reorderPt == '') { error = error + '\nReorder Point: Please enter a reorder point for the product.'; } else if (reorderPt.match(!numericExpression)) { error = error + '\nReorder Point: Please enter numeric values only.'; } } function validate_Weight() { var weight = document.getElementById('ctl00$ContentPlaceHolder1$txtWeight').value; if (weight == '') { error = error + '\nProduct Weight: Please enter the weight of the product.'; } else if(weight.match(!numericExpression)) { error = error + '\nProduct Weight: Please enter numeric values only.'; } } function validate_Tax() { var tax = document.getElementById('ctl00$ContentPlaceHolder1$txtTax').value; if (tax == '') { error = error + '\nTax Amount: Please enter a price value for the product.'; } else if(tax.match(!numericExpression)) { error = error + '\nTax Amount: Please enter numeric values only.'; } } function validate_Description() { var description = document.getElementById('ctl00$ContentPlaceHolder1$txtDesc').value; if(description.length>250) { error = error + '\nProduct Description: You have reached beyond the character limit.'; } }



LinkBack URL
About LinkBacks


Reply With Quote


Bookmarks