473,320 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

validation for dynamic multiple text fileds

hi guys,im new to this forum
could anyone help me to solve this problem for me..

In my site im generating multiple text boxes and i need to wirte validations for that....
Expand|Select|Wrap|Line Numbers
  1. <form id="form1" name="form1" method="post" action="">
  2.   <input name="cc1" type="text" id="cc1" value="0" />
  3.   <br />
  4. <input name="cc2" type="text" id="cc2" value="0" />
  5. <br />
  6. <input name="cc3" type="text" id="cc3" value="0" />
  7. <br />
  8. <input name="cc4" type="text" id="cc4" value="0" />
  9. <br />
  10. <input name="" type="submit" onclick="return valid()" />
  11. </form>
  12.  
  13.  
Expand|Select|Wrap|Line Numbers
  1. function emptyvalid(elem,altxt){
  2. var txt = document.getElementById(elem).value;
  3. if(txt == ""){
  4. alert(altxt);
  5. return false;
  6. }
  7. return true;
  8. }
  9. function valid(){
  10. for(i=1;i<10;i++){
  11. if(emptyvalid("cc"+i,"not empty")==false){
  12. return false;
  13. }
  14. }
  15. }
  16.  
May 12 '08 #1
2 1028
Logician
210 100+
Uses the element names not IDs:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <input name="" type="submit" onclick="return valid(this.form,'cc','Empty')" />
  3. ...........
  4. function valid(formRef, prefix, warnText)
  5. {
  6.   for(var i=1, elem, found=false; (elem=formRef[ prefix+i ]) && !found;   i++)
  7.    if( !elem.value.match(/\S/) )
  8.    {
  9.      alert( prefix + i +'\n\n' + warnText );
  10.      found=true;
  11.    }
  12.  
  13.  return !found;
  14. }
  15.  
May 12 '08 #2
Uses the element names not IDs:
Expand|Select|Wrap|Line Numbers
  1.  
  2. <input name="" type="submit" onclick="return valid(this.form,'cc','Empty')" />
  3. ...........
  4. function valid(formRef, prefix, warnText)
  5. {
  6.   for(var i=1, elem, found=false; (elem=formRef[ prefix+i ]) && !found;   i++)
  7.    if( !elem.value.match(/\S/) )
  8.    {
  9.      alert( prefix + i +'\n\n' + warnText );
  10.      found=true;
  11.    }
  12.  
  13.  return !found;
  14. }
  15.  
thank u Logician....... your code works fine....thank so muuch
May 13 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lorn | last post by:
I'm trying to figure out a way to create dynamic lists or possibly antother solution for the following problem. I have multiple lines in a text file (every line is the same format) that are...
5
by: Helen | last post by:
Hi I'm using ASP.NET's standard validators to display error messages when people don't fill in required fields on my form. The error messages currently show as soon as the form is loaded, but...
1
by: Liz | last post by:
I have a page with several dropdownlists, several text boxes and several buttons which perform calculations. I need to validate one dropdownlist (not the whole page) with the click of one button. I...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.