User Name Password Register
DaniWeb IT Discussion Community
All
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 397,600 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,674 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

Javascript alert not working

Join Date: Sep 2005
Posts: 660
Reputation: digital-ether has a spectacular aura about digital-ether has a spectacular aura about 
Rep Power: 5
Solved Threads: 38
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Practically a Master Poster

Help Re: Javascript alert not working

  #4  
Jan 23rd, 2007
Originally Posted by vssp View Post
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!
Reply With Quote  
All times are GMT -4. The time now is 6:58 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC