How to get value of input type array in Java Script

How to get value of input type array in Java Script

<html>
 <head>Codelizar</head>
 <title>Codelizar Blogs</title>
 <body>
  <input type="text" name="username[]" value="" />
  <input type="text" name="username[]" value="" />
  <input type="text" name="username[]" value="" />
  <input type="text" name="username[]" value="" />
  <input type="text" name="username[]" value="" />
  <input type="text" name="username[]" value="" />
  <input type="button" value="getname" onclick="functgetname();" />
 </body>
</html>

<script type="text/javascript">
 function getvalues(){
   var getid = document.getElementsByName('username[]');
   for (var i = 0; i <getid.length; i++) {
   var singleval=getid[i];
    alert("username["+i+"].value="+singlevalue.value);
 }
}
</script>

 

Leave a Reply

Your email address will not be published. Required fields are marked *