#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    48
    Rep Power
    16

    Making Contact_Name a mandatory Form field


    I have this Form that works successfully (I know it's not state-of-the-art).
    I simply want to add code to make Contact Name field mandatory. Can you help me?

    Code:
    <script type="text/javascript">
    function checkemail(){
    var str=document.myform.email_address.value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(str))
    testresults=true;
    else {
    alert("Please input a valid email address!");
    return false;
    }
    if(document.myform.agree.checked!=1) {
    alert("Please check the box to agree to the Terms.");
    return false;
    }
    if(document.myform.ans.value.toLowerCase()!="white") {
    alert("Please answer security question correctly: Black or White?");
    return false;
    }
    return true;
    }
    </script>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,987
    Rep Power
    375
    you just need another if statement to check whether name was empty or not and if empty do an alert.

    if (something == "" ) {
    alert..
    }
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    48
    Rep Power
    16

    thanks, but...


    I tried this without success, any other help will be appreciated:

    <script type="text/javascript">
    function checkemail(){
    var str=document.myform.email_address.value;
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if (filter.test(str))
    testresults=true;
    else {
    alert("Please input a valid email address!");
    return false;
    }
    if(document.myform.agree.checked!=1) {
    alert("Please check the box to agree to the Terms.");
    return false;
    }
    if(document.myform.contact_name.value!=0) {
    alert("Please enter your full name.");
    return false;
    }
    if(document.myform.ans.value.toLowerCase()!="white") {
    alert("Please answer security question correctly: Black or White?");
    return false;
    }
    return true;
    }
    </script>
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    50
    Rep Power
    35
    Try...

    Code:
    <script type="text/javascript">
    	function checkemail(){
    		var str=document.myform.email_address.value;
    		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    		if (filter.test(str))
    			testresults=true;
    		else {
    			alert("Please input a valid email address!");
    			return false;
    		}
    		if(document.myform.agree.checked!=1) {
    			alert("Please check the box to agree to the Terms.");
    			return false;
    		}
    		if(document.myform.contact_name.value == "") {
    			alert("Please enter your full name.");
    			return false;
    		}
    		if(document.myform.ans.value.toLowerCase()!="white") {
    			alert("Please answer security question correctly: Black or White?");
    			return false;
    		}
    		return true;
    	}
    </script>
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Posts
    48
    Rep Power
    16

    Thanks


    Thanks alot for the help

IMN logo majestic logo threadwatch logo seochat tools logo