I have 4 input form fields and when user enters data in any number of fields like he enter data in 2 fields and left 2 fields blank like(123, ,456, ,), i need to check on blur event so that it has to check for empty fields and once empty fields exits then it has to sort out all the data presented fields and then placed back to input fields like (456,123, , ,).
i am new to java script and i have no idea how to implement this , please help me thanks.
Checking for a b lur event will not help to detect empty fields because the fields will most likely be empty because they were never accessed to put anything in them in the first place.
Validating if a field is completely empty is relatively easy but first you need to define what “empty” means. Is the field empty if the person enters a dozen spaces in the field or only when nothing at all is entered?
Your example shows numbers for each entered value. Are numbers the only valid entries or would letters and other characters also be acceptable?
Once you define just what you want then writing a few lines of JavaScript to perform that validation will be easy but at the moment there are too many unanswered questions.
Using JQuery to perform form field validation is using a Jumbo jet to travel to work when you live just one street from where you work and the nearest airport is ten miles away.
Your question is not very clear. When do you want to do the checking ? on blur of what? each field or after a click of a button… ? And what do you mean sort out the data? you mean in descending order (from highest number to lowest) ?
And one more thing, do you mind using jQuery as a library ?