Using JS to control the Select label's default selection based on the data received __JS

Source: Internet
Author: User

This is in the last unit of the BDQN project, do an OA project, interim requirements Control Select selection:

<TD align= "Left" >
	<input type= "hidden" value= "${u.usersex}" id= "Sex" >
	<select name= " U.usersex "width=" 30% "id=" gender ">
		<option value=" Women "id=" woman "> Women </option>
		<option Value = "Male" id= "man" > </option>
	</select>
</td>


Here is the code in JS:

<script type= "Text/javascript" >
			
			var sex = document.getElementById ("Sex"). Value;
			if (sex = = "Man") {
				document.getElementById ("Gender"). Options[1].selected=true;
			} else{
				document.getElementById ("Gender"). Options[0].selected=true;
			}
			Check userName
			function CheckName () {
				var name = document.getElementById ("UserName"). Value;
				if (name = = NULL | | | name = = "") {
					alert ("User name cannot be empty!");
					return;
				}
			
			Check Usertel
			function Checktel () {
				var tel = document.getElementById ("Usertel"). Value;
				if (tel = = NULL | | tel = = "") {
					alert ("Cell phone number cannot be empty!");
					return;
				}
				if (Tel.length!=) {
					alert ("Please enter the correct 11-digit mobile number.") ");
					return;
				}
			
			Returns the previous page
			function Backit () {
				history.back ();
			}
			
			Commit
			function SaveIt ()
			{
				document.forms[0].submit ();
			}
			
</script>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.