Q: Django templat
Q: How to remove
The influence of f
--- abstract: 'The
Rapids midfielder
The present disclo
Epidemiology of cu
// Copyright 2015
"A lot of people a
--- abstract: 'In

Terry Farrell (dir
Q: Adding custom
Ford announced thi
{ "action": {
Q: how to remove
On Wednesday, the
In this series, I
Dental fluorosis a
Preliminary crysta
Miguel Roca Migue
Q: Using the same function in 3 sub-pages for different input names I have a form where I have to enter data into 3 input boxes. My JS script is: What I want is that when the form is submitted the function 'validate' will be called and if any of the 3 input values is empty, it will return false and show an alert. In this example, I want an alert to show if I leave any of the 3 input boxes blank. The problem is that I have 3 inputs with the same name. When I leave any of them empty it always shows an error no matter which one of them I don't fill in. Does anyone know how I can fix this problem? A: There is no way to do what you want. You have to do one of the following: Change the names of your input boxes so that they are unique, or Wrap each of them in a div, and in the validation function check if any of the divs are not empty. Edit: Here is the code I used to make the code working:

You can make your own javascript which changes the value of all the divs, but it's not practical for large numbers of fields. And please, don't ever use 'onclick' event handler to submit forms, use 'onsubmit' event handler. A: Use array form data in Js. So that it will check with all elements. First put input box and same class name to all that you want to validate and then change javascript as shown in below code. JavaScript var error_msg = ""; var msg = []; function validate() { if (error_msg.length > 0) { alert(error_msg); return false; } else { alert("valid form"); return true; } } if (msg.length > 0) { alert(msg); } HTML Code: JavaScript Code: for(var i = 0; i < document.forms.length; i++){ var forms = document.forms[i]; var input = document.getElementsByName("inp"+i); var msg = ""; if(input.length) { msg = input.length == 0 ? "Your " + i + " number must be filled." : ""; } if(msg.length){ alert(msg); return false; }else{ alert("valid form"); return true; } } Here is the jsfiddle link for this example: Click here for jsfiddle demo link I hope this will help you. A: Instead of using the onsubmit attribute of the form, call a function that iterates over each input in a particular set (e.g. just the inputs with class=set) and check if it's empty. The function should return true or false based on your criteria.
// JavaScript Code function validate() { // First, iterate over each input. // Don't use 'class' as the selector. The ID should be unique for each input, so // using it here is ok, but not advisable. var inputs = document.forms["form1"].getElementsByTagName("input"); var totalErrors = 0; for(var i = 0; i < inputs.length; i++) { if(inputs[i].value != "" || inputs[i].type == "text") { return true; } else { // Add an error to the 'error' array. totalErrors++; } } if(totalErrors > 0) { alert("Please fill in all fields"); return false; } else { alert("valid form");