Originally Posted by
vssp
Hai friends
I am using array "name " field for example
<input name="prod_image[]" type="file" class="Textfield" id="prod_image[]"/> *</td>
When I try to validate the text box NULL or not using Javascript ,I unable to validate
Please any one advice me
[HTML]
var value = document.getElementById('prod_image[]').value;
[/HTML]
That should get you the value of the input of id "prod_image[]".
The only problem that I can think of is if you have more than one id of "prod_image[]".
Example:
[HTML]<input name="prod_image[]" type="file" class="Textfield" id="prod_image[]"/>
<input name="prod_image[]" type="file" class="Textfield" id="prod_image[]"/>
<input name="prod_image[]" type="file" class="Textfield" id="prod_image[]"/>[/HTML]
Then document.getElementById('prod_image[]') will only return the first input element.
If you have multiple inputs like above you can iterate through them using the DOM method, getElementsByTagName().
Eg:
[HTML]var inputs = document.getElementsByTagName('input');
for (var i = 0; i < inputs.length; i++) {
if (inputs[i].type == 'file') { // check if this is a file
// do your validation here...
}
}[/HTML]
The problem with method is that you will get all input elements in the document via document.getElementsByTagName('input'); while all you want are the input elements in the form you are validating.
To get elements only in the form you will use:
[HTML]document.forms['form_name'].getElementsByTagName('input');[/HTML]
where 'form_name' is the name of your form.