Results 1 to 1 of 1

Thread: I need to disable some of the required fields in a form or script

  1. #1
    Join Date
    May 2007
    Location
    Atlanta,Ga
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question I need to disable some of the required fields in a form or script

    To anyone willing to help:

    I had a form build for my website: http://www.driverscdlstaffing.com/cd...plication.html

    The problem isthe fields are required basically for the whole form. I want to know how to disable a few select required fields on the form . You can visit the page above for the form and I've included my script js below. I only want to change a few fields to not required. Applicants try to fill out the form but get frustrated when fields are required that don't pertain to them. Any help would be greatly appreciated. I will paste a smals sample of the script js below for you to see. If you need more let me know! Of course you can upload the page above in your HTML editor to see the HTML and form settings. it's an email form.
    Thanks,
    Curtis Carpenter



    Please see partial script below:
    Code:
    function validate_app_data()
    {
    	var frm = document.forms[0];
    
    	if (frm.Application_Type[0].checked == false && frm.Application_Type[1].checked == false && frm.Application_Type[2].checked == false && frm.Application_Type[3].checked == false && frm.Application_Type[4].checked == false) {
    		alert("Your must choose an application type!");
    		frm.Application_Type[0].focus();
    		return false;
    	}
    	if (frm.Application_Type[1].checked == true){
    		if (frm.school_name.value == '') {
    			alert("The name of the school you graduated from is required!");
    			frm.school_name.style.backgroundColor = '#ffff00';
    			frm.school_name.focus();
    			return false;
    		} 
    		if (frm.school_phone_area.value == "" && frm.school_phone_prefix.value == "" && frm.school_phone_suffix.value == "") {
    			alert("School phone number is required!");
    			frm.school_phone_area.style.backgroundColor = '#ffff00';
    			frm.school_phone_prefix.style.backgroundColor = '#ffff00';
    			frm.school_phone_suffix.style.backgroundColor = '#ffff00';
    			frm.school_phone_area.focus();
    			return false;
    		}
    		if (frm.school_phone_area.length < 3 || isNaN(frm.school_phone_area.value)) {
    			alert("School phone number is invalid!");
    			frm.school_phone_area.style.backgroundColor = '#ffff00';
    			frm.school_phone_area.focus();
    			return false;
    		}
    		if (frm.school_phone_prefix.length < 3 || isNaN(frm.school_phone_prefix.value)) {
    			alert("School phone number is invalid!");
    			frm.school_phone_prefix.style.backgroundColor = '#ffff00';
    			frm.school_phone_prefix.focus();
    			return false;
    		}
    		if (frm.school_phone_suffix.length < 4 || isNaN(frm.school_phone_suffix.value)) {
    			alert("School phone number is invalid!");
    			frm.school_phone_suffix.style.backgroundColor = '#ffff00';
    			frm.school_phone_suffix.focus();
    			return false;
    		}
    		if (frm.school_graduation_date.value == '') {
    			alert("Graduation date is required!");
    			frm.school_graduation_date.style.backgroundColor = '#ffff00';
    			frm.school_graduation_date.focus();
    			return false;
    		}
    	} 
    	if (frm.Name.value == '') {
    		alert("Your first name is required!");
    		frm.Name.style.backgroundColor = '#ffff00';
    		frm.Name.focus();
    		return false;
    	}
    	if (frm.Lastname.value == '') {
    		alert("Your last name is required!");
    		frm.Lastname.style.backgroundColor = '#ffff00';
    		frm.Lastname.focus();
    		return false;
    	}
    	if (frm.homeaddress.value == '') {
    		alert("Your home address is required!");
    		frm.homeaddress.style.backgroundColor = '#ffff00';
    		frm.homeaddress.focus();
    		return false;
    	}
    	if (frm.City.value == '') {
    		alert("Please enter a city of residence!");
    		frm.City.style.backgroundColor = '#ffff00';
    		frm.City.focus();
    		return false;
    	}
    	if (frm.HomeState.value == "State") {
    		alert("Please choose your state of residence!");
    		frm.HomeState.style.backgroundColor = '#ffff00';
    		frm.HomeState.focus();
    		return false;
    	}
    	if (frm.Zip.value == '') {
    		alert("Please enter your zipcode!");
    		frm.Zip.style.backgroundColor = '#ffff00';
    		frm.Zip.focus();
    		return false;
    	}
    	if (isNaN(frm.Zip.value)) {
    		alert("Zipcode must be numeric!");
    		frm.Zip.style.backgroundColor = '#ffff00';
    		frm.Zip.focus();
    		return false;
    	}
    	if (frm.Zip.value.length < 5) {
    		alert("Zipcode must be at least 5 digits!");
    		frm.Zip.style.backgroundColor = '#ffff00';
    		frm.Zip.focus();
    		return false;
    	}
    	if (frm.Dobmonth.value == 'Month') {
    		alert("Please choose the month of your birth!");
    		frm.Dobmonth.style.backgroundColor = '#ffff00';
    		frm.Dobmonth.focus();
    		return false;
    	}
    	if (frm.DOBday.value == 'Day') {
    		alert("Please choose the day of your birth!");
    		frm.DOBday.style.backgroundColor = '#ffff00';
    		frm.DOBday.focus();
    		return false;
    	}
    	if (frm.DOByear.value == 'Year') {
    		alert("Please choose the year of your birth!");
    		frm.DOByear.style.backgroundColor = '#ffff00';
    		frm.DOByear.focus();
    		return false;
    	}
    	if (frm.city_born.value == '') {
    		alert("Please enter the birth city!");
    		frm.city_born.style.backgroundColor = '#ffff00';
    		frm.city_born.focus();
    		return false;
    	}
    	if (frm.State_born.value == 'State') {
    		alert("Please choose your birth state!");
    		frm.State_born.style.backgroundColor = '#ffff00';
    		frm.State_born.focus();
    		return false;
    	}
    	if (frm.ss1.value == '' && frm.ss2.value == '' && frm.ss3.value == '') {
    		alert("Please enter your social security number!");
    		frm.ssl.style.backgroundColor = '#ffff00';
    		frm.ss2.style.backgroundColor = '#ffff00';
    		frm.ss3.style.backgroundColor = '#ffff00';
    		frm.ss1.focus();
    		return false;
    	}
    	if (frm.ss1.length < 3 || frm.ss2.length < 2 || frm.ss3.length < 4) {
    		alert("Your social security number is invalid!");
    		frm.ssl.style.backgroundColor = '#ffff00';
    		frm.ss2.style.backgroundColor = '#ffff00';
    		frm.ss3.style.backgroundColor = '#ffff00';
    		frm.ss1.focus();
    		return false;
    	}
    	if (isNaN(frm.ss1.value) || isNaN(frm.ss2.value) || isNaN(frm.ss3.value)) {
    		alert("Social security number must be numeric!");
    		frm.ssl.style.backgroundColor = '#ffff00';
    		frm.ss2.style.backgroundColor = '#ffff00';
    		frm.ss3.style.backgroundColor = '#ffff00';
    		frm.ss1.focus();
    		return false;
    	}
    	if (frm.areacode.value == '' && frm.prefix.value == '' && frm.suffix.value == '') {
    		alert("Please enter your home phone number!");
    		frm.areacode.style.backgroundColor = '#ffff00';
    		frm.prefix.style.backgroundColor = '#ffff00';
    		frm.suffix.style.backgroundColor = '#ffff00';
    		frm.areacode.focus();
    		return false;
    	}
    	if (frm.areacode.length < 3 || frm.prefix.length < 3 || frm.suffix.length < 4) {
    		alert("Your home phone number is invalid!");
    		frm.areacode.style.backgroundColor = '#ffff00';
    		frm.prefix.style.backgroundColor = '#ffff00';
    		frm.suffix.style.backgroundColor = '#ffff00';
    		frm.areacode.focus();
    		return false;
    	}
    	if (isNaN(frm.areacode.value) || isNaN(frm.prefix.value) || isNaN(frm.suffix.value)) {
    		alert("Home phone number must be numeric!");
    		frm.areacode.style.backgroundColor = '#ffff00';
    		frm.prefix.style.backgroundColor = '#ffff00';
    		frm.suffix.style.backgroundColor = '#ffff00';
    		frm.areacode.focus();
    		return false;
    	}
    	if (frm.cellareacode.value != '' || frm.cellprefix.value != '' || frm.cellsuffix.value != '') {
    		if (frm.cellareacode.length < 3 || frm.cellprefix.length < 3 || frm.cellsuffix.length < 4) {
    			alert("Your cell phone number is invalid!");
    			frm.cellareacode.style.backgroundColor = '#ffff00';
    			frm.cellprefix.style.backgroundColor = '#ffff00';
    			frm.cellsuffix.style.backgroundColor = '#ffff00';
    			frm.cellareacode.focus();
    			return false;
    		}
    		if (isNaN(frm.cellareacode.value) || isNaN(frm.cellprefix.value) || isNaN(frm.cellsuffix.value))
    		{
    			alert("Cell phone number must be numeric!");
    			frm.cellareacode.style.backgroundColor = '#ffff00';
    			frm.cellprefix.style.backgroundColor = '#ffff00';
    			frm.cellsuffix.style.backgroundColor = '#ffff00';
    			frm.cellareacode.focus();
    			return false;
    		}
    	}
    	if (frm.email.value != '' && check_email(frm.email.value) == false) {
    		alert('Email format is invalid!');
    		frm.email.style.backgroundColor = '#ffff00';
    		frm.email.focus();
    		return false;
    	}
    	if (frm.best_time.value == '') {
    		alert('Please enter the best time to reach you!');
    		frm.best_time.style.backgroundColor = '#ffff00';
    		frm.best_time.focus();
    		return false;
    	}
    	if (frm.best_time.value.indexOf(":") == -1 && (frm.best_time.value.indexOf("AM") == -1 || frm.best_time.value.indexOf("PM") == -1 || frm.best_time.value.indexOf("am") == -1 || frm.best_time.value.indexOf("pm") == -1)) {
    		alert('Best time has invalid format!');
    		frm.best_time.style.backgroundColor = '#ffff00';
    		frm.best_time.focus();
    		return false;
    	}
    Last edited by tech_support; 05-09-2007 at 06:41 AM. Reason: Added code tags and removed personal information

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
  •