我有一个常规选择元素,然后是多个特定的选择元素,这些元素会根据常规选择的内容而改变。(这里的示例功能:http://jsfiddle.net/YPsqQ/1115/)我只是想确保第二个选择了某个东西/有一个值。
请注意,即使为特定的选择标记选择了选项,也会显示响应消息。
我试过了:
HTML:
<select class="industry_types" name="industry_types" id="industry_types">
<option value="">Select an industry</option>
<option value="Agriculture-and-Mining">Agriculture and Mining</option>
<option value="Business-Services">Business Services</option>
<option value="Computer-and-Electronics">Computer and Electronics</option>
<option value="Consumer-Services">Consumer Services</option>
<option value="Education">Education</option>
<option value="Energy-and-Utilities">Energy and Utilities</option>
<option value="Financial-Services">Financial Services</option>
<option value="Government">Government</option>
<option value="Health-Pharmaceuticals-and-Biotech">Health, Pharmaceuticals, and Biotech</option>
<option value="Hospitality-and-Cuisine">Hospitality & Cuisine</option>
<option value="Manufacturing">Manufacturing</option>
<option value="Media-and-Entertainment">Media and Entertainment</option>
<option value="Real-Estate-and-Construction">Real Estate and Construction</option>
<option value="Retail">Retail</option>
<option value="Telecommunications">Telecommunications</option>
<option value="Transportation-and-Storage">Transportation and Storage</option>
<option value="Travel-Recreation-and-Leisure">Travel Recreation and Leisure</option>
<option value="Software-and-Internet">Software and Internet</option>
</select>
<select class="Agriculture-and-Mining sub_industry_type" name="Agriculture_Mining" id="sub_industry_type">
<option value="">Select Agriculture & Mining subcategory</option>
<option value="Farming and Ranching">Farming and Ranching</option>
<option value="Fishing Hunting and Forestry and Logging">Fishing, Hunting and Forestry and Logging</option>
<option value="Mining and Quarrying">Mining and Quarrying</option>
<option value="Agriculture & Mining Other">Agriculture & Mining Other</option>
</select>
<select class="Business-Services sub_industry_type" name="Business_Services" id="sub_industry_type">
<option value="">Select Business Services subcategory</option>
<option value="Accounting and Tax Preparation">Accounting and Tax Preparation</option>
<option value="Advertising Marketing and PR">Advertising, Marketing and PR</option>
<option value="Data and Records Management">Data and Records Management</option>
<option value="Facilities Management and Maintenance">Facilities Management and Maintenance</option>
<option value="HR and Recruiting Services">HR and Recruiting Services</option>
<option value="Legal Services">Legal Services</option>
<option value="Management Consulting">Management Consulting</option>
<option value="Payroll Services">Payroll Services</option>
<option value="Sales Services">Sales Services</option>
<option value="Security Services">Security Services</option>
<option value="Business Services Other">Business Services Other</option>
</select>
<select class="Computer-and-Electronics sub_industry_type" name="Computer_Electronics" id="sub_industry_type">
<option value="">Select Computers & Electronics subcategory</option>
<option value="Audio, Video and Photography">Audio, Video and Photography</option>
<option value="Computers, Parts and Repair">Computers, Parts and Repair</option>
<option value="Consumer Electronics, Parts and Repair">Consumer Electronics, Parts and Repair</option>
<option value="IT and Network Services and Support">IT and Network Services and Support</option>
<option value="Instruments and Controls">Instruments and Controls</option>
<option value="Network Security Products">Network Security Products</option>
<option value="Networking equipment and Systems">Networking equipment and Systems</option>
<option value="Office Machinery and Equipment">Office Machinery and Equipment</option>
<option value="Peripherals Manufacturing">Peripherals Manufacturing</option>
<option value="Semiconductor and Microchip Manufacturing">Semiconductor and Microchip Manufacturing</option>
<option value="Computer and Electronics Other">Computer and Electronics Other</option>
</select>
<select class="Consumer-Services sub_industry_type" name="Consumer_Services" id="sub_industry_type">
<option value="">Select Consumer Services subcategory</option>
<option value="Automotive Repair and Maintenance">Automotive Repair and Maintenance</option>
<option value="Funeral Homes and Services">Funeral Homes and Services</option>
<option value="Laundry and Dry Cleaning">Laundry and Dry Cleaning</option>
<option value="Parking Lots and Garage Management">Parking Lots and Garage Management</option>
<option value="Personal Care">Personal Care</option>
<option value="Photofinishing Services">Photofinishing Services</option>
<option value="Consumer Services Other">Consumer Services Other</option>
</select>
<select class="Education sub_industry_type" name="Education" id="sub_industry_type">
<option value="">Select Education subcategory</option>
<option value="Colleges and Universities">Colleges and Universities</option>
<option value="Elementary and Secondary Schools">Elementary and Secondary Schools</option>
<option value="Libraries, Archives and Museums">Libraries, Archives and Museums</option>
<option value="Sports, Arts, and Recreation Instruction">Sports, Arts, and Recreation Instruction</option>
<option value="Technical and Trade Schools">Technical and Trade Schools</option>
<option value="Test Preparation">Test Preparation</option>
<option value="Education Other">Education Other</option>
</select>
<select class="Energy-and-Utilities sub_industry_type" name="Energy_Utilities" id="sub_industry_type">
<option value="">Select Energy & Utilities subcategory</option>
<option value="Alternative Energy Sources">Alternative Energy Sources</option>
<option value="Gas and Electric Utilities">Gas and Electric Utilities</option>
<option value="Gasoline and Oil Refineries">Gasoline and Oil Refineries</option>
<option value="Sewage Treatment Facilities">Sewage Treatment Facilities</option>
<option value="Waste Management and Recycling">Waste Management and Recycling</option>
<option value="Water Treatment and Utilities">Water Treatment and Utilities</option>
<option value="Energy and Utilities Other">Energy and Utilities Other</option>
</select>
<select class="Financial-Services sub_industry_type" name="Financial_Services" id="sub_industry_type">
<option value="">Select Financial Services subcategory</option>
<option value="Bank">Bank</option>
<option value="Credit Cards and Related Services">Credit Cards and Related Services</option>
<option value="Credit Unions">Credit Unions</option>
<option value="Insurance and Risk Management">Insurance and Risk Management</option>
<option value="Investment Banking and Venture Capital">Investment Banking and Venture Capital</option>
<option value="Lending and Mortgage">Lending and Mortgage</option>
<option value="Personal Financial Planning and Private Banking">Personal Financial Planning and Private Banking</option>
<option value="Securities Agents and Brokers">Securities Agents and Brokers</option>
<option value="Trust, Fiduciary, and Custody Activities">Trust, Fiduciary, and Custody Activities</option>
<option value="Financial Services Other">Financial Services Other</option>
</select>
<select class="Government sub_industry_type" name="Government" id="sub_industry_type">
<option value="">Select Governmental subcategory</option>
<option value="Bank">Governmental Department</option>
</select>
<select class="Health-Pharmaceuticals-and-Biotech sub_industry_type" name="Health_Pharmaceutical_Biotech" id="sub_industry_type">
<option value="">Select Health & Pharmaceuticals subcategory</option>
<option value="Biotechnology">Biotechnology</option>
<option value="Diagnostic Laboratories">Diagnostic Laboratories</option>
<option value="Doctors and Health Care Practitioners">Doctors and Health Care Practitioners</option>
<option value="Hospitals">Hospitals</option>
<option value="Medical Devices">Medical Devices</option>
<option value="Medical Supplies and Equipment">Medical Supplies and Equipment</option>
<option value="Outpatient Care Centers">Outpatient Care Centers</option>
<option value="Personal Health Care Products">Personal Health Care Products</option>
<option value="Pharmaceuticals">Pharmaceuticals</option>
<option value="Residential and Long-term Care Facilities">Residential and Long-term Care Facilities</option>
<option value="Veterinary Clinics and Services">Veterinary Clinics and Services</option>
<option value="Health, Pharmaceuticals, and Biotech Other">Health, Pharmaceuticals, and Biotech Other</option>
</select>
<select class="Manufacturing sub_industry_type" name="Manufacturing" id="sub_industry_type">
<option value="">Select manufacturing subcategory</option>
<option value="Aerospace and Defense">Aerospace and Defense</option>
<option value="Alcoholic Beverages">Alcoholic Beverages</option>
<option value="Automobiles, Boats and Motor Vehicles">Automobiles, Boats and Motor Vehicles</option>
<option value="Chemicals and Petrochemicals">Chemicals and Petrochemicals</option>
<option value="Concrete, Glass and Building Materials">Concrete, Glass and Building Materials</option>
<option value="Farming and Mining Machinery and Equipment">Farming and Mining Machinery and Equipment</option>
<option value="Food and Dairy Product Manufacturing and Packaging">Food and Dairy Product Manufacturing and Packaging</option>
<option value="Furniture Manufacturing">Furniture Manufacturing</option>
<option value="Metals Manufacturing">Metals Manufacturing</option>
<option value="Nonalcoholic Beverages">Nonalcoholic Beverages</option>
<option value="Paper and Paper Products">Paper and Paper Products</option>
<option value="Plastics and Rubber Manufacturing">Plastics and Rubber Manufacturing</option>
<option value="Textiles, Apparel and Accessories">Textiles, Apparel and Accessories</option>
<option value="Tools, Hardware and Light Machinery">Tools, Hardware and Light Machinery</option>
<option value="Manufacturing Other">Manufacturing Other</option>
</select>
<select class="Media-and-Entertainment sub_industry_type" name="Media_Entertainment" id="sub_industry_type">
<option value="">Select Media and Entertainment subcategory</option>
<option value="Motion Picture Exhibitors">Motion Picture Exhibitors</option>
<option value="Motion Picture and Recording Producers">Motion Picture and Recording Producers</option>
<option value="Newspapers, Books, and Periodicals">Newspapers, Books, and Periodicals</option>
<option value="Performing Arts">Performing Arts</option>
<option value="Radio, Television Broadcasting">Radio, Television Broadcasting</option>
<option value="Media and Entertainment Other">Media and Entertainment Other</option>
</select>
<select class="Real-Estate-and-Construction sub_industry_type" name="Real_Estate_Construction" id="sub_industry_type">
<option value="">Select Real-Estate-and-Construction subcategory</option>
<option value="Architecture, Engineering and Design">Architecture, Engineering and Design</option>
<option value="Construction Equipment and Supplies">Construction Equipment and Supplies</option>
<option value="Construction and Remodeling">Construction and Remodeling</option>
<option value="Property Leasing and Management">Property Leasing and Management</option>
<option value="Real Estate Agents and Appraisers">Real Estate Agents and Appraisers</option>
<option value="Real Estate Investment and Development">Real Estate Investment and Development</option>
<option value="Real Estate and Construction Other">Real Estate and Construction Other</option>
</select>
<select class="Retail sub_industry_type" name="Retail" id="sub_industry_type">
<option value="">Select Retail subcategory</option>
<option value="Automobile Dealers">Automobile Dealers</option>
<option value="Automobile Parts and Supplies">Automobile Parts and Supplies</option>
<option value="Beer, Wine and Liquor Stores">Beer, Wine and Liquor Stores</option>
<option value="Clothing and Shoe Stores">Clothing and Shoe Stores</option>
<option value="Department Stores">Department Stores</option>
<option value="Florist">Florist</option>
<option value="Furniture Stores">Furniture Stores</option>
<option value="Gasoline Stations">Gasoline Stations</option>
<option value="Grocery and Specialty Stores">Grocery and Specialty Stores</option>
<option value="Hardware and Building Material Dealers">Hardware and Building Material Dealers</option>
<option value="Jewelry, Luggage, and Leather Goods">Jewelry, Luggage, and Leather Goods</option>
<option value="Office Supplies Stores">Office Supplies Stores</option>
<option value="Restaurants and Bars">Restaurants and Bars</option>
<option value="Sporting Goods, Hobby, Books and Music Stores">Sporting Goods, Hobby, Books and Music Stores</option>
<option value="Retail Others">Retail Others</option>
</select>
<select class="Travel-and-Recreation-Leisure sub_industry_type" name="Travel_Recreation_Leisure" id="sub_industry_type">
<option value="">Select Travel Recreation and Leisure subcategory</option>
<option value="Amusement Parks and Attractions">Amusement Parks and Attractions</option>
<option value="Cruise Ship Operations">Cruise Ship Operations</option>
<option value="Gambling and Gaming Lodging">Gambling and Gaming Lodging</option>
<option value="Participatory Sports and Recreation">Participatory Sports and Recreation</option>
<option value="Passenger Airlines">Passenger Airlines</option>
<option value="Rental Cars">Rental Cars</option>
<option value="Resorts and Casinos">Resorts and Casinos</option>
<option value="Spectator Sports and Teams">Spectator Sports and Teams</option>
<option value="Taxi, Buses and Transit Systems">Taxi, Buses and Transit Systems</option>
<option value="Travel Agents and Services">Travel Agents and Services</option>
<option value="Travel, Recreations and Leisure Other">Travel, Recreations and Leisure Other</option>
</select>
<select class="Hospitality-and-Cuisine sub_industry_type" name="Hospitality_Cuisine" id="sub_industry_type">
<option value="">Select Hospitality & Cuisine subcategory</option>
<option value="Bed and Breakfasts">Bed and Breakfasts</option>
<option value="Hotel">Hotel</option>
<option value="Hotel">Hostel</option>
<option value="Resturant">Restaurant</option>
<option value="Resturant">Resort</option>
<option value="Bar, Pubs and Public houses">Bar/Pub or Public house</option>
<option value="Tourist Agency">Night club</option>
<option value="Serviced apartments">Serviced apartments</option>
</select>
<select class="Transportation-and-Storage sub_industry_type" name="Transportation_Storage" id="sub_industry_type">
<option value="">Select Transportation and Storage subcategory</option>
<option value="Air Couriers and Caro Services">Air Couriers and Caro Services</option>
<option value="Airport, Harbor, and Terminal Operations">Airport, Harbor, and Terminal Operations</option>
<option value="Freight Hauling (Rail and Truck)">Freight Hauling (Rail and Truck)</option>
<option value="Marine and Inland Shipping">Marine and Inland Shipping</option>
<option value="Moving Companies and Services">Moving Companies and Services</option>
<option value="Postal, Express Delivery and Couriers">Postal, Express Delivery and Couriers</option>
<option value="Warehousing and Storage">Warehousing and Storage</option>
<option value="Transportation and Storage Other">Transportation and Storage Other</option>
</select>
<select class="Telecommunications sub_industry_type" name="Telecommunications" id="sub_industry_type">
<option value="">Select Telecommunications subcategory</option>
<option value="Cable and Television Providers">Cable and Television Providers</option>
<option value="Telecommunications Equipment and Accessories">Telecommunications Equipment and Accessories</option>
<option value="Telephone Service Providers and Carriers">Telephone Service Providers and Carriers</option>
<option value="Video and Teleconferencing">Video and Teleconferencing</option>
<option value="Wireless and Mobile">Wireless and Mobile</option>
<option value="Telecommunications Other">Telecommunications Other</option>
</select>
<select class="Software-and-Internet sub_industry_type" name="Software_Internet" id="sub_industry_type">
<option value="">Select Software and Internet subcategory</option>
<option value="Data Analytics, Management, and Internet">Data Analytics, Management, and Internet</option>
<option value="E-Commerce and Internet Business">E-Commerce and Internet Business</option>
<option value="Games and Gaming">Games and Gaming</option>
<option value="Software">Software</option>
<option value="Software and Internet Other">Software and Internet Other</option>
</select>
JS :(隐藏并显示子类别,具体取决于在常规类别中选择的内容)
$(function() {
$('.general_select').change(function(){
$('.sub_industry_type').hide();
$('.' + $(this).val()).fadeIn();
});
});
AJAX电话:
$(document).ready(function (e) {
$('.add_business_form').on('submit',(function(e) {
e.preventDefault();
var formData = new FormData(this);
$.ajax({
type:'POST',
url: $(this).attr('action'),
data:formData,
cache:false,
contentType: false,
processData: false,
dataType: "json",
success:function(response){
switch(response.message){
case 'company_name_error':
company_name_error();
break;
case 'phone_number_0_error':
phone_number_0_error();
break;
case 'company_description_error_1':
company_description_error_1();
break;
case 'company_description_error_2':
company_description_error_2();
break;
case 'industry_types_error':
industry_types_error();
break;
case 'Sub_industry_types_error':
Sub_industry_types_error();
break;
case 'company_keywords_error':
company_keywords_error();
break;
case 'company_website_error':
company_website_error();
break;
case 'company_contact_name_error':
company_contact_name_error();
break;
case 'company_contact_position_error':
company_contact_position_error();
break;
case 'contact_phone_number_error':
contact_phone_number_error();
break;
case 'file_is_not_image':
file_is_not_image();
break;
case 'No_file_selected':
No_file_selected();
break;
case 'wrong_logo_extention':
Wrong_extention();
break;
case 'logo_too_big':
logo_too_big();
break;
case 'unknown_error':
unknown_error();
break;
case 'form_success':
form_success();
break;
}
},
error: function(data){
console.log(data)
}
});
}));
});
PHP(常规选择元素):
if(empty($industry_types)){
$response["message"] = 'industry_types_error';
$errors++;
}
PHP(特定选择元素):
if (!in_array($Agriculture_Mining, array("Farming and Ranching", "Fishing Hunting and Forestry and Logging", "Mining and Quarrying", "Agriculture & Mining Other"))) {
$response["message"] = 'Sub_industry_types_error';
$errors++;
}else{}
if (!in_array($Business_Services, array("Accounting and Tax Preparation", "Advertising Marketing and PR", "Data and Records Management", "Facilities Management and Maintenance", "HR and Recruiting Services", "Legal Services", "Management Consulting", "Sales Services", "Security Services", "Business Services Other"))) {
$response["message"] = 'Sub_industry_types_error';
$errors++;
}else{}
// etc. . . for each specific select.