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 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
About the
:checkedselectorWhat you need to do is, find
inputelements that have thenameattribute 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#myformis not strictly necessary, but it speeds things up a bit (because the browser does not need to hunt through the entire page to find thename="formpage"elements).