I have radioboxes
<form method="post" id="myform">
<label>A</label>
<input type="radio" name="formtype" value = "1" checked="checked">
<label>B</label>
<input type="radio" name="formtype" value = "2">
<label>C</label>
<input type="radio" name="formtype" value = "3">
<button type="submit"/>Submit</button>
<div class = "space"></div>
</form>
My ajax submission function is:
$.ajax(
{
data:
{
type: /////What do开发者_如何学Python I put HERE <-------
},
url: 'in.php',
complete: function (XMLHttpRequest, textStatus)
{
$('#longurl').val(XMLHttpRequest.responseText);
}
});
I am trying to pass in the value of the checked of the 3 radio boxes into something called type, I was wondering what should I put in the arrowed space above (/////What do I put HERE). I was trying to use $('#formtype').val() but it wasn't working.
Thanks
$('#myform input[name="formtype"]:checked').val()
About the :checked
selector
What you need to do is, find input
elements that have the name
attribute of "formtype"
, then filter to only those that are selected (due to the nature of radioboxes, there will be at most one), then get value of that. The #myform
is not strictly necessary, but it speeds things up a bit (because the browser does not need to hunt through the entire page to find the name="formpage"
elements).
try this
$('#myform input[name="formtype"]:checked').val()
精彩评论