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

Thread: Validating group of Listboxes plus textboxes....complicated

  1. #1
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Validating group of Listboxes plus textboxes....complicated

    Hi,

    I have a group of 24 list boxes plus 24 text boxes. I have two groups like this. The user will choose from each list boxes and enter a 3 digit number beside it. The user can choose minimum of 4 items and enter the digits in the corresponding text boxes. The user can choose any 4 out of 24 choices.

    Validation is : without choosing at least 4 list boxes along with filled text boxes the form will not be submitted.

    I would really appreciate if someone could help.
    I am attaching the html file in a zip folder in the attachment below.

    Thanks in advance.

    Gulluman.


    Attachment 270

  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

    Form validation is best done server side but, using javascript, this method will work if javascript is enabled in the client's browser and they don't try to pull a 'fast one' by hacking the script -

    First give your two tables each these unique ids:

    HTML Code:
    <table id="table1" BORDER="3" align='center' >
    and

    HTML Code:
    <table id="table2" BORDER="3" align='center' >
    Next, change your onsubmit event like so:

    Code:
    onsubmit="return validate();"
    Finally put this script in the head:

    Code:
    <script type="text/javascript">
    function val(table){
    var inps=document.getElementById(table).getElementsByTagName('input')
    var texts=new Array()
    var tcount=count=0
    for (var i_tem = 0; i_tem < inps.length; i_tem++)
    if ( inps[i_tem].type=='text' ){
    texts[tcount]=inps[i_tem]
    tcount++
    }
    for (var i_tem = 0; i_tem < texts.length; i_tem++)
    if ( texts[i_tem].value.length==3&&!isNaN(parseInt(texts[i_tem].value)) )
    count++
    if (count>3)
    return true;
    else
    return false;
    }
    
    function validate() {
    if (val('table1')&&val('table2'))
    return true;
    else {
    alert ('You must choose at least 4 course areas in each section,\n and furnish a course level number for each.')
    return false;
    }
    }
    </script>
    Notes: This only satisfies the requirements you mentioned, any positive, whole 3 digit number may be used in the text fields and the originally selected options may all be retained.
    - John
    ________________________

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

  3. #3
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Thank you

    This sounds okay though I approached in a different method. I will try this in the page. Thanks a lot for all your help.

    Gulluman

  4. #4
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Can't really figure out the problem.

    I have been trying the above code to implement in my script. But something is wrong that I cant really debug. I spent a lot of time on this. Below is what my HEAD Javascript Validation function looks like. It gives me error whenever i submit. I checked with other codes and it works 100% before I implemented the given codes for listbox checking.

    I was also wodering how I can check whether the user not only entered the three digits but also has selected an item from the list box.



    Thanks a lot for your help. I am only stuck with this then whole form would be complete. Please help !

    Gulluman
    Last edited by gulluman; 03-12-2006 at 11:20 PM.

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It gives me error whenever i submit.
    That's helpful... any info?
    If you can get the error Firefox or Opera gives, that would be even more useful; IE's errors tend to be rather... er... categorical.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Twey
    That's helpful... any info?
    If you can get the error Firefox or Opera gives, that would be even more useful; IE's errors tend to be rather... er... categorical.
    Thanks.
    I did not mean any IE error. The error is that the form does not complete the validation and that can be due to some coding problem. And I am not sure where is the wrong coding that is not letting the validation to be complete.

    Thanks so much.

    Gulluman

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You mean it always returns false?
    Could you...
    PLEASE: Include the URL to your problematic webpage that you want help with.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    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

    You changed the function val(). Also once the function validate() returns for whatever reason as true, false or undefined, it will stop checking other information on the page.
    - John
    ________________________

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

  9. #9
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I attached the html file as test3.txt in the attachment. The webpage is not yet online so i am sending you a demo version. Just change the test3.txt to test3.html and you will see the page.



    Thanks
    Last edited by gulluman; 03-12-2006 at 11:21 PM.

  10. #10
    Join Date
    Feb 2006
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    You changed the function val(). Also once the function validate() returns for whatever reason as true, false or undefined, it will stop checking other information on the page.
    The function val(table) only checks the first table. So even when the first table returns true, the function val(table) does not check the second table, in fact it directly submits the form.

    Yes i did change the Val() function but it does not help even with the previous one that you posted.

    I guess you understand what the problem is now.

    Thanks again

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
  •