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 374,612 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,400 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: 577 | Replies: 1
Reply
Join Date: Mar 2008
Posts: 6
Reputation: infernodeep is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
infernodeep infernodeep is offline Offline
Newbie Poster

validation for dynamic multiple text fields

  #1  
May 11th, 2008
hi there could any one solve this problem for me plzz.....

In my site iam generating multiple textfields and i need to wite validation for that
function valid(){

for(var i=0;i<4;i++){
if(document.getElementById('d'+i).value == ""){
alert("not empty");
return false;
}
return true;
}
}
<form name="f1">
<input name="cc1" id="d1" type="text" value="0" />
<input name="cc2" id="d2" type="text" value="0" />
<input name="cc3" id="d3" type="text" value="0" />
<input name="cc4" id="d4" type="text" value="0" />
<input name="submit" type="submit" onclick="return valid()" />
</form>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2008
Posts: 169
Reputation: Traicey is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 16
Traicey's Avatar
Traicey Traicey is offline Offline
Junior Poster

Re: validation for dynamic multiple text fields

  #2  
May 12th, 2008
The following code is checking if the text boxes that are named "text" have values
and if thats correct the code returns true and submit the form, all it does is checking if one of the text boxes have values, but if u want all the text boxes to have values u have to validate each one of them.

// "Text" elements are textboxes

var validText = false;

for (var i = 0; i<document.MyForm.elements.length; i++) {
if (document.MyForm.elements[i].name = "Text" (
if (document.MyForm.elements[i].value != "") {
validText = true;
}
}
}

return validText;
Some people get so rich they lose all respect for humanity. That's how rich I want to be.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 8:44 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC