Home Javascript validation for a html form not working

# Javascript validation for a html form not working

oliver thomas
1#
oliver thomas Published in 2017-12-07 21:34:59Z
 ----------SOLVED------------ I'm trying to do a validation for a form so that if any of the fields are left blank, there is an alert and the form wont go through, but it is still inputting null values into the database function validateAdd() { var a = document.add_product.product_id.value; var b = document.add_product.brand.value; var c = document.add_product.model.value; var h = document.add_product.description.value; var d = document.add_product.cam_mpx.value; var e = document.add_product.storage.value; var f = document.add_product.more_storage.value; var g = document.add_product.price.value; if (a == "" || b == "" || c == "" || d == "" || e == "" || f = "" || g == "" || h == "" || a == null || b == null || c == null || d == null || e == null || f = null || g == null || h == null) { alert("All fields must be filled in"); return false; } } 


ericw31415
2#
 Well, on these two lines, you do f = "" and f = null instead of f == "" and f == null: if (a == "" || b == "" || c == "" || d == "" || e == "" || f = "" || g == "" || h == "" || a == null || b == null || c == null || d == null || e == null || f = null || g == null || h == null) {  You would have noticed to look there from Uncaught ReferenceError: Invalid left-hand side in assignment being errored to the console. I would suggest that you shorten that down to if (!(a && b && c && d && e && f && g && h)) {  because it's way easier to debug.