jQuery validates a set of inputs

	//check the selected gene
	var trO = $("tr[id^='td'][id$='Gene']:visible");//Selected virus
	var tName = trim($(trO).children(":first").text());//Selected virus name for alert
	var gene = "virus."+$(trO).attr("id").replace("td","").replace("Gene","")+"Gene";//所选病毒英文名
	var geneO = gene+"Other";
	if($("[name='"+gene+"']").is(":radio")){ //The option of the selected gene is in the form of radio
		var k = $("[name='"+gene+"']").length;//Number of selected gene radios
		var l = $("[name='"+gene+"']").index($("[name='"+gene+"']:checked")) + 1;//Selected gene sequence number+ 1
		if(l == 0){
			alert("Please select the selected gene of "+tName+"");
			return false;
		}else if(l == k){ //The last one is selected, "other" exists for all relevant options
			if(trim($("[name='"+geneO+"']").val())==null || trim($("[name='"+geneO+"']").val())==""){
				alert("Please enter "+tName+"the specific content of the selected gene "other"");
				return false;
			}
		}
	}else{ //The selected gene option is in text form
		var on = trim($("[name='"+gene+"']").val());
		if(on==null || on==""){
			alert("Please enter the selected gene of "+tName+"");
			return false;
		}
	}
]

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326096773&siteId=291194637