最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jquery get radio button value - Stack Overflow

programmeradmin2浏览0评论

all i want is to use the .get function to retrieve the selected/checked radio button value, i think i got the code right, but the sequence is kinda wrong

$.get('burgerorder_check.php', function(data) {
                inputVal = $('input[type=radio][name=timeslot]:checked').val();
            });

then after i get the inputVal, i want to reload a particular div with that specific input

    setInterval(getData,1000);
    getData();
    function getData(){
    if( inputField ) {
    $("#timeslot").load('burgerorder_check.php?dateselect='+inputField+'&inputselect=a'+inputVal);
    };

any help? So far the inputVal value is null :(

Full block of code :

$(document).ready(function(){
        var inputField;
        var inputVal;


        $("#dateslot").change(function(){
        inputField = $('#dateslot').val();
        });

        $.get('burgerorder_check.php', function(data) {
            inputVal = $('input[type=radio][name=timeslot]:checked').val();
        });

        setInterval(getData,1000);
        getData();
        function getData(){
        if( inputField ) {
        $("#timeslot").load('burgerorder_check.php?dateselect='+inputField+'&inputselect=a'+inputVal);
        };
        };


});

all i want is to use the .get function to retrieve the selected/checked radio button value, i think i got the code right, but the sequence is kinda wrong

$.get('burgerorder_check.php', function(data) {
                inputVal = $('input[type=radio][name=timeslot]:checked').val();
            });

then after i get the inputVal, i want to reload a particular div with that specific input

    setInterval(getData,1000);
    getData();
    function getData(){
    if( inputField ) {
    $("#timeslot").load('burgerorder_check.php?dateselect='+inputField+'&inputselect=a'+inputVal);
    };

any help? So far the inputVal value is null :(

Full block of code :

$(document).ready(function(){
        var inputField;
        var inputVal;


        $("#dateslot").change(function(){
        inputField = $('#dateslot').val();
        });

        $.get('burgerorder_check.php', function(data) {
            inputVal = $('input[type=radio][name=timeslot]:checked').val();
        });

        setInterval(getData,1000);
        getData();
        function getData(){
        if( inputField ) {
        $("#timeslot").load('burgerorder_check.php?dateselect='+inputField+'&inputselect=a'+inputVal);
        };
        };


});
Share Improve this question edited Oct 11, 2013 at 5:55 Crays asked Oct 11, 2013 at 5:34 CraysCrays 2,50810 gold badges28 silver badges33 bronze badges 4
  • What is inputField? Is inputVal a global variable? You need to share the plete block of code, this code part seems inplete to correctly find the issue. – Ankit Jaiswal Commented Oct 11, 2013 at 5:53
  • i've added the full block of code in, i'm not quite sure about the global variable, i know inputField is not, but in this case, i have 2 pages, which one is use to only generate the radio box form so that i can change it accordingly, but now what i want is to keep it selected by retrieving its value and sending it back again. Or is there another way to do so? – Crays Commented Oct 11, 2013 at 5:56
  • What I can understand with your ment is that you have a form containing a set of radio buttons. When the user selects a radio button, you want that value to be sent to the server script and keep the radio button selected. Is it correct? – Ankit Jaiswal Commented Oct 11, 2013 at 6:06
  • yes i want it to be kept selected but i am also refreshing that div that load the page every second. – Crays Commented Oct 11, 2013 at 6:17
Add a ment  | 

4 Answers 4

Reset to default 4
$('input[name='radio_button_name']:checked').val() 

Try this

I hope to be able to help you

Jquery Code:
$("#ssss").bind("change",function(value){
    var test = $(this).children(":checked").val();
    alert(test)
})

HTML Code:
<div ng-app="App" id="ssss">
   <input type="radio" name='test'  value="red">  Red <br/>
   <input type="radio" name='test' value="green"> Green <br/>
   <input type="radio" name='test' value="blue"> Blue <br/>
</div>

http://jsfiddle/5qbG6/6/

Try This:

$("input[name='RadioButtonId']:checked").val()

$.get('burgerorder_check.php', function(data) {
                inputVal = $("input[name='timeslot']:checked").val()
            });
var timeslot = $("#timeslot:checked").val();
alert(timeslot );
发布评论

评论列表(0)

  1. 暂无评论