Results 1 to 4 of 4

Thread: Dropdown list validation

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    malaysia
    Posts
    57

    Dropdown list validation

    How to validate this kind of dropdown list? (on form submit)
    The first list is empty...An alert message will popup if the list selected is empty...

    <select name="bnRoom">
    <option></option>
    <option>MONDAY</option>
    <option>TUESDAY</option>
    <option>WEDNESDAY</option>
    <option>THURSDAY</option>
    <option>FRIDAY</option>
    </select>

  2. #2
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727
    Heres how using javascript, you haven't given the elements any values so i have added them in, and there is no reason to put a blank item in your select.

    <html>
    <head>
    <title>Untitled Document</title>
    <script language="javascript">
    function fCheck(val1){
    if (val1 == ""){
    alert("Please select a value");
    return false
    }else{
    return true
    }
    }
    </script>
    </head>

    <body>
    <form action="http://www.mcfc.co.uk" method="post" onSubmit="return fCheck(bnRoom.value);">
    <select name="bnRoom">
    <option></option>
    <option value="MONDAY">MONDAY</option>
    <option value="TUESDAY">TUESDAY</option>
    <option value="MONDAY">WEDNESDAY</option>
    <option value="THURSDAY">THURSDAY</option>
    <option value="FRIDAY">FRIDAY</option>
    </select >
    <input type="submit" value="click me!">
    </form>
    </body>
    </html>

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    malaysia
    Posts
    57
    Thanx davebat...

  4. #4

    Thread Starter
    Member
    Join Date
    Feb 2004
    Location
    malaysia
    Posts
    57
    What if I have more than one dropdown list to be validate?
    How to code in the Form OnSubmit?

Posting Permissions

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



Click Here to Expand Forum to Full Width