In my form, there is a field called Work_Location[] which is an array. I need to determine whether it is empty or not. Here is the JavaScript code:
var ele=document.myForm.elements['Work_Location[]'];
alert(ele.length);
if(ele.length==0)
{
alert("Please enter Work_Location");
//document.myForm.EMail.focus() ;
return false;
}
The issue here is that alert(ele.length) is returning undefined instead of the number of elements in the array.
Here's the HTML code for reference:
<form action="trainer_register.php" name="myForm" enctype="multipart/form-data" class="form-horizontal" method="post" id="my-from" onsubmit="return validate();">
<div class="input_fields_wrap">
<div class="form-group">
<label class="col-md-3 control-label" for="example-text-input">Preferred Work Location</label>
<div class="col-md-3">
<input type="text" id="loc" name="Work_Location[]" class="form-control" >
</div>
<button class="add_field_button">Add More Locations</button>
</div>
</div>