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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2010
    Location
    Windsor, United Kingdom
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    The Case construct, Please help.

    Hi everyone, I've started a course on web design and I'm busy with a assignment on Javascript. I need to make a contact list which I'm nearly done with but I'm stuck with one bit, validating select lists, I want to do it using a case construct but I'm not sure how cause mine doesn't want to work. Will someone please help me?

    Code:
         case "email":
            var emailRegExp = /[a-z0-9]/i; /* Should contain at least 1 letter and can have numbers */
            var email2RegExp = /[@]/; /* There has to be a @ character */
            var email3RegExp = /[.]/; /* Should contain at least 1 . */
            var email4RegExp = /[ ]/; /* Can not have any spaces */
            if (emailRegExp.test(fld.value) == true && email2RegExp.test(fld.value) == true && email3RegExp.test(fld.value) == true && email4RegExp.test(fld.value) == false) {
              fld.valid = true;
            }
            break;
    			
    			case "day": /* Day of birth, Select list */
    				if (dd.value="no") == false; {
    				 fld.valid = true;
    				}
    				break;
    		  
    			case "month": /* Month of birth, Select list */
    				if (mm.value="no") == false; {
    				 fld.valid = true;
    				}
    				break;
    				
    			case "year": /* Year of birth, Select list */
    				if (yyyy.value="no") == false; {
    				 fld.valid = true;
    				}
    				break;
    				
    			case "select_list":
    				if (not(select_list.value=no)) {
    				 fld.valid = true;
    				}
    				break;
    				
    			}
      }
    
      function validate(frm) {
        for (i = 0; i < frm.length - 1; i++) {
          ValidateField(frm.elements[i])
        }
      }
    
      function validation(frm) {
        var validation_text = "";
    
        if (frm.fname.valid == false) {
          validation_text += "First Name Field is either empty or incorrect, only letters, spaces and 	hyphens allowed.\n\n"
        }
    
        if (frm.lname.valid == false) {
          validation_text += " Last Name Field is either empty or incorrect, only letters, spaces and 	hyphens allowed.\n\n"
        }0
    
     		if (frm.housename.valid == false) {
          validation_text += "Your House name Field is either empty or incorrect, letters, spaces and hyphens 	allowed.\n\n"
        }
    		
    		if (frm.streetname.valid == false) {
          validation_text += "Your Street name Field is either empty or incorrect, letters, spaces and hyphens 	allowed.\n\n"
        }
    		
    		if (frm.townname.valid == false) {
          validation_text += "Your Town name Field is either empty or incorrect, letters, spaces and hyphens 	allowed.\n\n"
        }
    		
    		if (frm.county.valid == false) {
          validation_text += "Your County Field is either empty or incorrect, letters, spaces and hyphens 	allowed.\n\n"
        }
    
    		if (frm.postcode.valid == false) {
          validation_text += "Postcode Field is either empty or incorrect, Capital letters and numbers 	allowed.\n\n"
        }
    
        if (frm.teleph.valid == false) {
          validation_text += "Telephone number Field is either empty or incorrect, only numbers allowed.\n\n"
        }
    
        if (frm.email.valid == false) {
          validation_text += "Email Field is either empty or incorrect, letters, numbers, @, . , and no 	spaces allowed.\n\n"
        }
    		
    		if (frm.dd.valid == false) {
    			validation_text += "You have not selected your Day Of Birth. Please use the list. \n\n"
    		}
    		
    		if (frm.mm.valid == false) {
    			validation_text += "You have not selected your Month Of Birth. Please use the list. \n\n"
    		}
    		
    		if (frm.yyyy.valid == false) {
    			validation_text += "You have not selected your Year Of Birth. Please use the list. \n\n"
    		}
    		
    		if (frm.select_list.valid == false) {
    			validation_text += "You have not selected your best form of contact. Please use the list. \n\n"
    		}
    
        if (validation_text == "") {
          validation_text += "Thank you for entering your details!"
          alert(validation_text);
          return true;
        }
        else {
          alert(validation_text)
          return false;
        }
      }
    		  
    </script>
    </head>
    
    <body>
        <form name="ContactList" method="post" action="mailto:lourens.erasmus@btinternet.com" onSubmit="validate(this); return validation(this);">
        <table border="0" align="center" cellspacing="5" cellpadding="5" width="600">
          <tr>
    			<th align="center" colspan="2">
            <h2>
              <b>Contact List</b></h2>
          </th>
          </tr>
    			<tr>
      			<td>
              First Name
            </td>
            <td>
              <input type="text" name="fname">
            </td>
          </tr>
          <tr>
            <td>
              Last Name
            </td>
            <td>
              <input type="text" name="lname">
            </td>
          </tr>
    			<tr>
            <td>
              House Name or Number
            </td>
            <td>
              <input type="text" name="housename">
            </td>
          </tr>
    			<tr>
            <td>
              Street Name
            </td>
            <td>
              <input type="text" name="streetname">
            </td>
          </tr>
    			<tr>
            <td>
              Town
            </td>
            <td>
              <input type="text" name="townname">
            </td>
          </tr>
    			<tr>
            <td>
              County
            </td>
            <td>
              <input type="text" name="county">
            </td>
          </tr>
          <tr>
            <td>
              Postcode
            </td>
            <td>
              <input type="text" name="postcode">
            </td>
          </tr>
          <tr>
            <td>
              Telephone
            </td>
            <td>
              <input type="text" name="teleph">
            </td>
          </tr>
          <tr>
            <td>
              Email Address
            </td>
            <td>
              <input type="text" name="email">
            </td>
          </tr>
    			<tr>
            <td>
             Date Of Birth 
    				</td>
            <td>
             <select name="dd">
    					<option value="no">DAY</option>
    					<option value="1">01</option>
    					<option value="2">02</option>
    					<option value="3">03</option>
    					<option value="4">04</option>
    					<option value="5">05</option>
    					<option value="6">06</option>
    					<option value="7">07</option>
    					<option value="8">08</option>
    					<option value="9">09</option>
    					<option value="10">10</option>
    					<option value="11">11</option>
    					<option value="12">12</option>
    					<option value="13">13</option>
    					<option value="14">14</option>
    					<option value="15">15</option>
    					<option value="16">16</option>
    					<option value="17">17</option>
    					<option value="18">18</option>
    					<option value="19">19</option>
    					<option value="20">20</option>
    					<option value="21">21</option>
    					<option value="22">22</option>
    					<option value="23">23</option>
    					<option value="24">24</option>
    					<option value="25">25</option>
    					<option value="26">26</option>
    					<option value="27">27</option>
    					<option value="28">28</option>
    					<option value="29">29</option>
    					<option value="30">30</option>
    					<option value="31">31</option>
    				 </select>
    				 <select name="mm">
    				  <option value="no">MONTH</option>
    				  <option value="Jan">January</option>
    					<option value="Feb">February</option>
    					<option value="Mar">March</option>
    					<option value="Apr">April</option>
    					<option value="May">May</option>
    					<option value="Jun">June</option>
    					<option value="Jul">July</option>
    					<option value="Aug">August</option>
    					<option value="Sept">September</option>
    					<option value="Oct">October</option>
    					<option value="Nov">November</option>
    					<option value="Dec">December</option>
    				 </select>
    				 <select name="yyyy">
    				  <option value="no">YEAR</option>
    					<option value="50">1950</option>
    					<option value="51">1951</option>
    					<option value="60">1952</option>
    					<option value="60">1953</option>
    					<option value="60">1954</option>
    					<option value="60">1955</option>
    					<option value="60">1956</option>
    					<option value="60">1957</option>
    					<option value="60">1958</option>
    					<option value="60">1959</option>
    					<option value="60">1960</option>
    					<option value="60">1961</option>
    					<option value="60">1962</option>
    					<option value="60">1963</option>
    					<option value="60">1964</option>
    					<option value="60">1965</option>
    					<option value="60">1966</option>
    					<option value="60">1967</option>
    					<option value="60">1968</option>
    					<option value="60">1969</option>
    					<option value="60">1970</option>
    					<option value="60">1971</option>
    					<option value="60">1972</option>
    					<option value="60">1973</option>
    					<option value="60">1974</option>
    					<option value="60">1975</option>
    					<option value="60">1976</option>
    					<option value="60">1977</option>
    					<option value="60">1978</option>
    					<option value="60">1979</option>
    					<option value="60">1980</option>
    					<option value="60">1981</option>
    					<option value="60">1982</option>
    					<option value="60">1983</option>
    					<option value="60">1984</option>
    					<option value="60">1985</option>
    					<option value="60">1986</option>
    					<option value="60">1987</option>
    					<option value="60">1988</option>
    					<option value="60">1989</option>
    					<option value="60">1990</option>
    					<option value="60">1991</option>
    					<option value="60">1992</option>
    					<option value="60">1993</option>
    					<option value="60">1994</option>
    					<option value="60">1995</option>
    					<option value="60">1996</option>
    					<option value="60">1997</option>
    					<option value="60">1998</option>
    					<option value="60">1999</option>
    					<option value="60">2000</option>
    					</select> 
            </td>
          </tr>
          <tr>
            <td>
              Best Time to Call
            </td>
            <td>
              <input type="radio" name="best" value="Morning">Morning<br>
              <input type="radio" name="best" value="Afternoon" checked>Afternoon<br>
              <input type="radio" name="best" value="Evening">Evening
            </td>
          </tr>
          <tr>
            <td>
              Best Form of Contact
            </td>
            <td>
              <select name="select_list">
                <option value="no">-Please Select-</option>
                <option value="Telephone">Telephone</option>
                <option value="Post">Post</option>
                <option value="Email">Email</option>
              </select>
            </td>
          </tr>
          <tr>
            <td align="center" colspan="2">
              <input type="submit" value="Submit">
            </td>
      </tr> </table> </form>
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,924
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Please restrict your code to the part giving trouble. No-one wants to wade through the whole thing. See MUST READ- How to post a JavaScript question! Para 3.

    Code:
    case "select_list":
    if (not(select_list.value=no)) {
    fld.valid = true;
    }
    should be

    Code:
    case "select_list":
    if (select_list.value != "no") {
    fld.valid = true;
    }
    Quizmaster: Which of the three British armed forces is known as "the senior service"?
    Contestant: The SS.

  • Users who have thanked Philip M for this post:

    loua84 (11-03-2010)

  • #3
    New to the CF scene
    Join Date
    Oct 2010
    Location
    Windsor, United Kingdom
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Sorry about that! Thank you for the help, it sorted out my problem!


  •  

    Posting Permissions

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