JQuery gets the value of of in the selected radio check box and drop down box

  • 2020-03-30 02:04:21
  • OfStack

Examples are as follows:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
<script type="text/javascript" src="jquery-1.3.min.js"></script>
<script type="text/javascript">
function aa(){
//Gets the value of the radio button
var a = $("input[name='sex'][checked]").val();
alert(a);
}
function bb(){
//Returns true if selected, false otherwise
var c = $("#a").attr("checked");
alert(c);
//Gets the value of a single check box
var d = $("input[name='checkName'][checked]").val();
alert(d);
//Gets the value of multiple check boxes
$("input[name='checkName'][checked]").each(function(){
if(this.checked)
alert($(this).val());
});
}
function checkWeek(){
//var $param = {};
$("#mPrefType").each(function(){
//    var key = $(this).attr("name");
//    if(!$param[key])
//        $param[key] = [];
//Get the value value
var value = $("##mPrefType option:selected").val();
alert(value);
//Get the required value
var name = $("##mPrefType option:selected").text();
alert(name);
});
}
</script>
</head>
<body>
Number:<input type = "text" value ="" name ="num1"/><br>
Number:<input type = "text" value ="" name = "num2"/><br>
<input type = "radio" value = "a"  name = "ss" />a
<input type = "radio" value = "b"  name = "ss" />b
<input type = "radio" value = "c"  name = "ss"/>c
<input type = "radio" value = "d"  name = "ss" >d<br>
<input type = "submit"  value = " submit "/> <br>
<hr>
<input type="radio" value=" male " name="sex" id="1" onclick="aa()"/> male 
<input type="radio" value=" female " name="sex" id="0" onclick="aa()"/> female <br>
<input type="button" value=" The gender of your choice " onclick="aa()"/><br>
<hr>
<input type="checkbox" name="checkName" value="aa" id="a"/>aa
<input type="checkbox" name="checkName" value="bb" id="b"/>bb
<input type="checkbox" name="checkName" value="cc"/>cc
<input type="checkbox" name="checkName" value="dd"/>dd<br>
<input type="button" value=" The value you selected is " onclick="bb()"/>
<hr>
<ul>
<li> Please choose ze </li>
<li>
<select id="mPrefType" name="mPrefType" class="inputS" onchange="checkWeek()">
<option value=0> Please select a :</option>
<option value=1> Monday </option>
<option value=2> Tuesday </option>
<option value=3> Wednesday </option>
<option value=4> Thursday </option>
<option value=5> Friday </option>
<option value=6> Saturday </option>
<option value=7> Sunday </option>
</select>
</li>
</ul>
</body>
</html> 


Related articles: