I’m trying to do some things in order, and I’m having some trouble.
- When the button with the id #sub_button is clicked,
- Make sure each element with class “.verify” has it’s own object value (see code)…
- … if not, blur that element (will run some other code and create an object for it).
-
AFTER the above IF check is COMPLETE (now all elements should have an object), THEN run function “isitgood”. (The “isitgood” function is running before all elements get their object values, which is done on blur)
$("#sub_button").click(function() { $(".verify").each(function(){ objtitle = $(this).attr('id'); if (!myObj[objtitle]) { $("#"+objtitle).blur(); // Define anything undefined } }); // end each isitgood(); }); // end click function function isitgood(){ if (myObj.login_id == "ok" && myObj.email == "ok") { // submit the form } else { // shows error } }
Also, once I get this executing in the right order, it would be nice to do some sort of .each loop to check if all the object values == “ok” instead of specifying all of them in the function. All of the names of the objects (ie. login_id, email) are the ID attr of any element with class name .verify.
Well, you could do a quick index check in the click callback:
This will check if you’re on the last element in the jQuery object, and if so, will run the
isitgood()function. This way, you make sure that you’re finished with the$.eachmethod before executingisitgood()