send name="" in jquery javascript?
So i have this:
yes: <input type="radio" value="Y" id="SCvoteY" name="vote"></input> no: <input type="radio" id="SCvoteN" value="N" name="vote"> </input>
How do i write that it should transfer name="vote" data ? #vote doesnt work, .vote either (guess it cause thats for class and ID) but what about name then?
function DoSCInsert(){
$("#SCres").html("please wait..");
var nocache = '0';
var data = { fID : $("#fID").val(), vote : $("#vote").val(), comment: $("#comment").val(), nocache: nocache };
$.get('insertSC.php', data, onSCInsertComplete);
}
And how do i shorten this, ive heard that you can you a function in jquery called serialize to pass strings but can you(if you know how) show example by this script how to pass it like this one does?
Updated code:
function DoSCInsert(){
$("#SCres").html("to sek..");
var nocache = '0';
var voteRadios = $('input[name="vote"]:checked');
var data = {`enter code here` fID : $("#fID").val(), voteRadios, numChecked: $(voteRadios).length, comment: $("#comment").val(), nocache: nocache };
$.get('insertSC.php', data, onSCInsertComplete);
}
insertSC.php:
<?p开发者_如何转开发hp
if($_GET['numChecked'] == '1'){
$fID= $_GET['fID'];
$vote= $_GET['vote'];
$comment= $_GET['comment'];
if(empty($vote)){ echo "blank"; }else{ echo $vote; }
}else{
echo $_GET["numChecked"];
}
?>
data = { voteValue: $('input[name="vote"]:checked').val() }
of course you can optimize the selector as you wish... and maybe add logic to make sure at least one of the radios is checked.
精彩评论