Thursday, 30 June 2011

Get all selected Ids of checkboxes exists in a div Through UQuery


//JavaScript, JQuery Code
function Get_Selected_Chk_Ids()
{
    var RetVal = "";
    var ChkId = "";
    var Ids = "";
   
    try
    {  
        $("#area_list_div :checked").each(function() {       
            ChkId = $(this).context.id;
            if(ChkId != "")
            {
                Ids += “,” + ChkId;
            }
          });
         
          if(Ids != "")
          {
              RetVal = Ids.substr(1);
          }
    }
    catch(err){}
   
    alert("Selected Area Ids : " + RetVal);
    return RetVal;
}


//HTML code

<input type='button' onclick=” Get_Selected_Chk_Ids();”>
<div id=’are_list_div’>
<input type='checkbox' id=’1’> India
<input type='checkbox' id=’2’> Sri Lanka
<input type='checkbox' id=’3’> Nepal
</div>

No comments:

Post a Comment