Assigning Text Box Values to a String Array in Javascript? -


is there way assign each of values enter multiple text boxes string array in javascript?

javascript

<script type="text/javascript">   var ch[];    function getallvalues() {    alert('entered');     for(var i=0;i<5;i++) {       ch.push(document.getelementsbyname("src")[i]);     };   alert(ch); } </script> 

home.jsp

<form method="post" name="myform" onsubmit="getallvalues();">//     <%         (int = 0; < 5; i++) {     %>     <input type="text" name="src"/ >     <%         }     %>     <input type="submit" value="submit"> </form>   var ch[]; 

here there 5 text boxes. want assign values entered here array using javascript.

does have idea how this? stuck on 2 days.

for(i=0;i<5;i++) {   ch.push(document.getelementsbyname("src")[i]); } 

edit

<% for(int i=0;i<5;i++) { %>         <input type="text" name="src" onblur="srcblur()" /> <% } %> 

...

var src = new array();  function srcblur(this) {   if(this == document.getelementsbyname("src")[0]) src[0] = this.value;   else if(this == document.getelementsbyname("src")[1]) src[1] = this.value;   else if(this == document.getelementsbyname("src")[2]) src[2] = this.value;   else if(this == document.getelementsbyname("src")[3]) src[3] = this.value;    if(src[0] && src[1] && src[2] && src[3] && src[4]) {     for(i=0;i<5;i++) {       ch.push(src[i]);     }   } } 

Comments

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -