•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 375,246 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,147 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2325 | Replies: 5
![]() |
•
•
•
•
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Javascript links not working (Web Browsers)
- Inserting dynamic values into Javascript variables (JavaScript / DHTML / AJAX)
- Javascript:void links not working. (Web Browsers)
- Issue with Javascript embedded in C# (ASP.NET)
- JavaScript problem in FF (JavaScript / DHTML / AJAX)
- JavaScript Timer (JavaScript / DHTML / AJAX)
- SQL Query inserts junk data as well (ASP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript and Firefox ISSUES
- Next Thread: Reply Back?


Linear Mode