SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    select list validation

    Hi,

    I am trying to implement a technique demonstrated here
    http://www.sitepoint.com/forums/show...ect+validation

    but can't get it to work.

    The relevant parts of the html are:

    HTML Code:
    <head>
    <script language="JavaScript" type="text/JavaScript" src="stock.js"></script>
    </head>
    
    <form name="move" onSubmit="return submitMove(this)">
    
    	<select name="to" size="1">
    		<option selected value="">Select One</option>
    		<option value="">- - - - - - -</option>
    		<option value="NI">Northern Ireland</option>
    		<option value="ENG">England</option>
    	</select>
    	<input type="submit" name="submit" value="MOVE" /></td>
    	
    </form>
    And stock.js contains the following:

    Code:
    function submitMove(move) {
    	if(move.to.value == 0) {
    		alert("You must choose a destination")
    		return false
    	}
    }
    Thank you for taking the time to read and reply to this probably dumb question.

  2. #2
    SitePoint Evangelist
    Join Date
    Mar 2006
    Location
    Sweden
    Posts
    451
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should be checking for an empty string value in your submitMove()-function, and not zero, since your options have the value of "". Or, you could check move.to.value.length against zero.

  3. #3
    SitePoint Addict palgrave's Avatar
    Join Date
    Jan 2006
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean

    Code:
    move.to.value == ""
    or

    Code:
    move.to.value.length == 0
    either will do?


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
  •