Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

foreach object/array in jQuery

I have a problem, i have X <input type="checkbox" /> in my code, now I want to foreach this object/array its out put. - look my code.

$("#denied_seekrs").click(function()
{ 
    if (!isCheckedById("selectname")) 
    { 
        alert ("Please select at least one event"); 
        return false; 
    } 
    else 
    { 
        alert( $("input[@id=selectname]:checked").val() ); //submit the form 
    } 
}); 

function isCheckedById(id) 
{ 
    var checked = $("input[@id="+id+"]:checked").length; 
    if (checked == 0) 
    { 
        return false; 
    } 
    else 
    { 
        return true; 
    } 
}

When I output it in alert i get a object, but if I have select 2 checkbox I what the value in this 2 checkboxes.

I hope I can be helpful and all here understand me :)

like image 957
ParisNakitaKejser Avatar asked Sep 02 '09 09:09

ParisNakitaKejser


1 Answers

How about

$("#denied_seekrs").click(function() {
    var checkedInputs = $("input:checked");
    var test = "";
    $.each(checkedInputs, function(i, val) {
        test += val.value+",";
    });
    test = test.substring(0,(test.length-1));
    alert(test);
});
like image 121
william Avatar answered Sep 22 '22 01:09

william