SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast hotdiggity's Avatar
    Join Date
    Aug 2004
    Location
    Brisbane
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Validate form field for a specific form

    Need to validate a drop down for a specific value, "OTHER". Not being a js coder, how do I get this to work?

    Code:
    	if((document.theForm.mobprovider.selectedIndex=="Other") &&
               (theForm.mobother.value =="" )){
    		bMissingFields = true;
    		strFields += "     Service provider :  Other - please specify \n";
    	}
    Code:
    <select name="mobprovider">
              <option value="">-- SELECT --</option>
              <option value="Telstra">Telstra</option>
              <option value="Optus">Optus</option>
              <option value="Other">Other - please specify</option>
            </select>
       Specify other:
            <input name="mobother" type="text" value="" size="12" maxlength="20" />

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by hotdiggity View Post
    Need to validate a drop down for a specific value, "OTHER". Not being a js coder, how do I get this to work?

    Code:
    	if((document.getElementById('mobprovider.value=="Other") &&
               (document.getElementById('mobother').value =="" )){
    		bMissingFields = true;
    		strFields += "     Service provider :  Other - please specify \n";
    	}
    Code:
    <select id="mobprovider" name="mobprovider">
              <option value="">-- SELECT --</option>
              <option value="Telstra">Telstra</option>
              <option value="Optus">Optus</option>
              <option value="Other">Other - please specify</option>
            </select>
       Specify other:
            <input id="mobother" name="mobother" type="text" value="" size="12" maxlength="20" />
    Make the changes I made (shown in Red), and it should work

  3. #3
    SitePoint Enthusiast hotdiggity's Avatar
    Join Date
    Aug 2004
    Location
    Brisbane
    Posts
    92
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks very much - that did it. Just need the ') before ".value" in the first line:

    Code:
    	if((document.getElementById('mobprovider').value=="Other") &&
               (document.getElementById('mobother').value =="" )){
    		bMissingFields = true;
    		strFields += "     Service provider :  Other - please specify \n";
    	}

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,061
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by hotdiggity View Post
    thanks very much - that did it. Just need the ') before ".value" in the first line:

    Code:
    	if((document.getElementById('mobprovider').value=="Other") &&
               (document.getElementById('mobother').value =="" )){
    		bMissingFields = true;
    		strFields += "     Service provider :  Other - please specify \n";
    	}
    Oops. Sorry


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
  •