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
__________________

Recommended Answers

All 5 Replies

What's the code for validation? Can you post it here?

hi R u know about the solution this issue !!!!!!!!!!!!

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

var value = document.getElementById('prod_image[]').value;

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:

<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[]"/>

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:

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... 

   }

}

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:

document.forms['form_name'].getElementsByTagName('input');

where 'form_name' is the name of your form.

Thanks digital-ether Its working

Thanks for your replay

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.