jquery Get Radio checkbox value and JS get check box value code

Source: Internet
Author: User

<div id= "Test1" >
<input id= "Radio1" type= "Radio" name= "Radio1" value= "man" >
People
<input id= "Radio2" type= "Radio" name= "Radio1" value= "Ghost" >
Ghost
</div>
There are two ways to implement this in relation to the above:
1, the use of Div ID implementation
#test1 input represents all input elements under the Test1 element
$ ("#test1 input"). Click (function () {
Alert ($ (this). attr ("value"));
2, get all the type of input element, because the single selection may choose one, so this is the currently selected radio box
var radio = $ (' input[type= "Radio"]);
Radio.click (function ()
{
Alert ($ (this). attr ("value")); Take value
});

Here is a Web page special effects get check box value code

<script>
function checkbox ()
{
var str=document.getelementsbyname ("box");
var objarray=str.length;
var chestr= "";
for (i=0;i<objarray;i++)
{
if (str[i].checked = = True)
{
Chestr+=str[i].value+ ",";
}
}
if (Chestr = "")
{
Alert ("Please first choose a hobby ~! ");
}
Else
{
Alert ("Your first choice is:" +chestr);
}
}
</script>
<a href= "http://www.111cn.net" > Web page Making Tutorials </a>Choose your hobby:
<input type= "checkbox" name= "box" id= "Box1" value= "diving"/> Diving
<input type= "checkbox" name= "box" id= "Box2" value= "Running"/> Running
<input type= "checkbox" name= "box" id= "Box3" value= "listening to music"/> Listening to music
<input type= "button" name= "button" id= "button" onclick= "checkbox ()" value= "Submit"/>

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.