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 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2002
    Location
    Noblesville, IN
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validate multiselect menu item

    how can i validate that at least one item is checked in a select menu?

    Code:
    <form>
      <select name="to" id="to" size="6" multiple>
        <option value="1">Hospital 1</option>
        <option value="2">Hospital 2</option>
        <option value="3">Hospital 3</option>
      </select>
    </form>
    Ed Ventura
    Graphic/Web Designer
    www.blackwatercompany.com

  • #2
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if (document.forms[0].to.selectedIndex == -1)
    {.....bad dog!


    }
    &nbsp;........ another wild guess ........

  • #3
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I think the default selectedIndex is -1 only when the size attribute is greater than 1. Otherwise, it's 0.

    Just FYI.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #4
    Regular Coder
    Join Date
    Aug 2003
    Posts
    383
    Thanks
    0
    Thanked 0 Times in 0 Posts
    validate multiselect menu item

    <select name="to" id="to" size="6" multiple>
    &nbsp;........ another wild guess ........

  • #5
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Indeed

    But, what I said is true, for single selects. Multiples are always -1 by default.
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”


  •  

    Posting Permissions

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