问题
How can i make when i chose a radio button On or Off to submit input id="kot" ?
<label><input type="radio" onClick="*???*" name="shfaq<?php echo $i; ?>" value="1" id="radiobuttonsondazh_0" <?php if($result['live']==1) echo 'checked'; ?> />Po</label>
<label><input type="radio" onClick="*???*" name="shfaq<?php echo $i; ?>" value="0" id="radiobuttonsondazh_1" <?php if($result['live']==0) echo 'checked'; ?> />Jo</label>
<input id="kot" name="soralivetitull" type="submit" value="Shfaq" style="margin-top:1em" onclick="setWTF(this.form.soralivetitull);" />
回答1:
Try it like this:
<script type="text/javascript">
function submitform()
{
document.forms["myform"].submit();
}
</script>
//give your form the id "myform"
<form id="myform" action="submit-form.php">
//and then call the function onCLick
<input type="radio" onClick="javascript: submitform()" ...
回答2:
Either you can make a form out of this and do something explained here:
W3Schools on form submitting or you can make a submit function via ajax:
$.ajax({
url: 'MyURLtoReceivePost',
type: 'POST',
cache : false,
data : data,
contentType: 'application/x-www-form-urlencoded; charset=utf-8',
success: function (response) {
console.log(response);
},
error: function () {
console.log("error");
}
});
In which you could just include your own data {parameter_name : value, parameter_name2 : value2} The information you can easily find in the jquery API
回答3:
http://api.jquery.com/submit/
$( "#radiobuttonsondazh_0" ).click(function() {
$( "#kot" ).submit();
});
来源:https://stackoverflow.com/questions/21531428/radio-button-on-click-submit-input