Reputation: 4325
The jsp page is not recognizing my array aa[]
in the line document.dd.aa[i].value
....
to be specific dd is my form name....
<script type="text/javascript">
function chk()
{
var errmsg = new String("");
var aa = new Array("t1","t2");
for(var i=0;i<=1;i++)
{
var ddd = document.dd.aa[i].value;
if(ddd=="")
{
errmsg += "Empty field:" +"\n";
}
}
alert(errmsg);
}
</script>
Thx in advance :DD...
Upvotes: -1
Views: 214
Reputation: 8401
var aa = new Array("t1","t2");
Above is not part of the form. So var ddd = document.dd.aa[i].value;
is wrong.
You can directly access aa array. So do like this.
var ddd = aa[i];
Upvotes: 4
Reputation: 119847
To access the array, it's simply:
var ddd = aa[i];
Also, it's better to create the array using literals:
var aa = ['t1','t2'];
If dd
is a form, then document.dd
returns the DOM form element named dd
. To access the elements, you need to traverse the element using DOM traversal methods, like getElementById
, getElementsByTagName
and so on.
Upvotes: 4