I am developing a web page with html and jquery. Many pages have forms with several input type text. I am trying to develop a jquery function to control if some inputs are empty or wrong.
I want to put all inputs values in an array. I have troubles when I try to read the text values, I get an object htmlinputelement:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function () { $(':button').click(function () { var elems = document.querySelectorAll('input[type=text]'); var array = jQuery.makeArray(elems); jQuery.each(array.valueOf(), function (i, valor) { if (valor == "") $('div:last').append("Error " + valor + '<br/>'); }); }); }); </script> <form action="page.html" method="post"> <input type="text" name="name" id="name" /><br /> <input type="text" name="surname" id="surname" /><br /> <input type="text" name="mail" id="mail" /><br /> <input type="text" name="number" id="number" /><br /> <input type="text" name="date" id="date" /><br /> <input type="text" name="place" id="place" /><br /> <div class="linea"> <input type="submit" name="send" value="SEND" /> <input type="reset" name="clear" value="CLEAR" /> <input type="button" name="check" value="CHECK" /> </div> </form> <div style="border: solid red; width: 250px; height: 450px;"></div> I have also used valor[0].value and valor.eq(0).val(), but I can´t get success.
How can I fix it?
Thanks.
makeArray, it's already gives you an array!