Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: validation many text box same name?

  1. #1
    Join Date
    Jul 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Exclamation validation many text box same name?

    Hi......
    Hello experts please give me a sample code for validating many text box with same.i knew for validate a number but i couldnt get how to validate for many text box with same name.

    regards
    satheesh kannan

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Since you haven't made it clear what we are validating on, you will have to make up your own rule for the highlighted part. Or you could tell me what we are validating on, and I could tell you what to put there:

    Code:
    <script type="text/javascript">
    function val_many(f, n){
    for (var e = f.elements, i = e.length - 1; i > -1; --i)
    if (e[i].type && e[i].type == 'text' && e[i].name && e[i].name == n && !(e[i].value something)){
    alert('Some Message');
    e[i].focus();
    return false;
    }
    return true;
    }
    </script>
    Then in the opening tag of your form:

    HTML Code:
    <form action="whatever" onsubmit="return val_many(this, 'some_name');">
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. The Following User Says Thank You to jscheuer1 For This Useful Post:

    satkannanab (07-29-2008)

  4. #3
    Join Date
    Jul 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re:text box validate same name

    Hi..
    Thanks for your kind reply.
    I need to validate some conditions .
    They are...1.not to be empty field,2.Only numerical,3.Fixed decimal of 4 digits only. These were the validation i have to do.
    return val_many(this, 'some_name');">
    is it some_name should be text box name or wat?.

    Thanks in advance,
    regards,
    satheesh kannan

  5. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I'm not clear on 3:

    Fixed decimal of 4 digits only
    Would:

    1

    be OK?

    How about:

    1.352

    ?

    What would be an example of the smallest number allowed? The largest? Is it that if decimals are used, only 4 places are allowed, or are 4 decimal places required?

    To answer your question, yes. You would replace some_name with the name of your text fields.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. The Following User Says Thank You to jscheuer1 For This Useful Post:

    satkannanab (07-29-2008)

  7. #5
    Join Date
    Jul 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re:

    3. point is to fixed maximum number of 4 digits only e.g: 1234
    No fraction s are allowed like 1.234.


    satheesh

  8. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    function val_many(f, n){
    for (var e = f.elements, i = e.length - 1; i > -1; --i)
    if (e[i].type && e[i].type == 'text' && e[i].name && e[i].name == n && (e[i].value == ''
    || isNaN(e[i].value - 0) || /\./.test(e[i].value) || e[i].value > 9999)){
    alert('Some Message');
    e[i].focus();
    return false;
    }
    return true;
    }
    </script>
    </head>
    <body>
    <form action="#" onsubmit="return val_many(this, 'some_name');">
    <input type="text" name="some_name"><br>
    <input type="text" name="some_name"><br>
    <input type="text" name="some_name"><br>
    <input type="text" name="some_name"><br>
    <input type="submit" value="Go!">
    </form>
    </body>
    </html>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. The Following User Says Thank You to jscheuer1 For This Useful Post:

    satkannanab (07-29-2008)

  10. #7
    Join Date
    Jul 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re:

    Hi......
    Thanks for ur kind and wonderful reply.
    Its alerting when the function encounters a problem,but after clicking ok
    in alert box the page getting load to next page.Its not focussing to the corresponding text box.

    I think the function is returning but not returning false;

    Waiting for ur reply,

    regards,
    satheesh kannan

  11. #8
    Join Date
    Jul 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Thanks yar...
    Its working fine.i just taken out the
    Code:
    e[i].focus();
    this code.
    But again i have a small problem.some text boxes are disabled in the same name.
    If i filled out correctly for all enabled text box,its being alerting for disabled text box too.HOw i can cure this too.


    Regards,
    satheesh kannan

  12. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Here (addition red):

    Code:
    if (e[i].type && e[i].type == 'text' && e[i].name && e[i].name == n && !e[i].disabled && (e[i].value == ''
    || isNaN(e[i].value - 0) || /\./.test(e[i].value) || e[i].value > 9999)){
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  13. #10
    Join Date
    Jul 2008
    Posts
    18
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re:

    Hi......
    Its alerting for all text boxes if its enabled or disabled.If i filled out all text boxs also it alerting the message.




    Waiting for ur reply,

    regards,
    satheesh kannan

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •