Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    combo box values?

    I have 2 combo boxes where you can move the items in combo box 1 to combo box 2. I want to validate that combo box 2 actually has something moved to it. How can I count the items in combo box 2. Combo box 2 will initially have no items in the box on page load. It is up to the user to move the items to combo box 2 and I want to make sure at least 1 item was moved.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Post the code. HTML and Javascript. Or post a link to a test page.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,121
    Thanks
    75
    Thanked 4,338 Times in 4,304 Posts
    First of all, there's no such thing as a "combo box" in HTML. That's an MSIE thing that allows you to *either* select from a dropdown *or* type in a new value. You can simulate that in HTML using JavaScript and both an <input type="text"> and <select>. Is *that* what you are talking about????

    Or do you really mean you have simply a pair of <select>s???

    If so, it's easy.

    Just do something like this:
    Code:
    function validateForm(form)
    {
        var found = false;
        for ( var i = 0; i < form.two.options.length; ++i )
        {
            if ( form.two.options[i].selected ) found = true;
        }
        if ( ! found )
        {
            alert("You must choose at least one widget");
            return false;
        }
        ... other form validation here ...
    
        return true; // if all validation succeeds
    }
    
    ...
    
    <form ... onsubmit="return validateForm(this);">
    ...
    <select name="one">
    ...
    </select>
    ...
    <select name="two">
    ...
    </select>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    nikko50 (12-01-2009)

  • #4
    New Coder
    Join Date
    Nov 2009
    Posts
    31
    Thanks
    1
    Thanked 0 Times in 0 Posts
    How anybody suppose to help when "OldPend.." taking them all. Dang !!!


  •  

    Posting Permissions

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