Hi
I want to extract all the names properties of the html form. I have 2 elements (Textarea and CheckBox) and I need to create 2 arrays with all the names of them, is to say, in the array1 all the checkbox names and in the array2 all the textarea names.
In this code I get the names but it print undefined values because the length of the arrays is the double size.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
</HEAD>
<BODY>
<FORM METHOD=POST ACTION="" name="solicitud" id="frm1">
<TABLE>
<TR>
<TD> <TEXTAREA id='text' NAME="text1" ></TEXTAREA></TD>
<TD> <INPUT id='check' TYPE="checkbox" NAME="check1"></TD>
</TR>
<TR>
<TD> <TEXTAREA id='text' NAME="text2" ROWS="" COLS="" disabled></TEXTAREA></TD>
<TD> <INPUT id='check' TYPE="checkbox" NAME="check2"></TD>
</TR>
<TR>
<TD> <TEXTAREA id='text' NAME="text3" ROWS="" COLS="" disabled></TEXTAREA></TD>
<TD> <INPUT id='check' TYPE="checkbox" NAME="check3"></TD>
</TR>
<TR>
<TD> <TEXTAREA id='text' NAME="text4" ROWS="" COLS="" disabled='disabled'></TEXTAREA></TD>
<TD> <INPUT id='check' TYPE="checkbox" NAME="check4" ></TD>
</TR>
</TABLE>
</FORM>
<script type="text/javascript">
var x=document.getElementById("frm1");
var j=x.length;
var texto=document.getElementsByTagName("TEXTAREA");
var check=document.getElementsByTagName("INPUT");
var jhon=new Array();
var jhon1=new Array();
alert(texto.length+" "+check.length);
for (var i=0;i<j;i++)
{
if(x.elements[i].id=="check"){
jhon[i]=x.elements[i].name;
}else if(x.elements[i].id=="text"){
jhon1[i]=x.elements[i].name;
}
}
for (var r=0;r<jhon.length;r++)
{
document.write(jhon[r]+" "+ jhon1[r]);
document.write("<br />");
}
alert(jhon.length);
alert(jhon1.length);
</script>
</BODY>
</HTML>
I use a conditional for filter it but not work.
Someone have any tips for me, please.
Muchas Gracias