views:

23

answers:

2
     <form>
  <input type="checkbox" id="m_q" name="m_q" value="271">Name</input><div name="status"></div>
   <input type="checkbox" id="m_q" name="m_q" value="271">Age</input><div name="status"></div>
   <input type="checkbox" id="m_q" name="m_q" value="271">ID</input><div name="status"></div>
  <input type="checkbox" id="m_q" name="m_q" value="271">Emp no</input><div name="status"></div>
 <input type="button" value="save" onclick="save" />
 </form>

 <script>
   function save()
    {
     $.post("/det/save_details/",snddata,
    function(data){
   if(data == 0 ){
   alert('data added');
   //How to disable the checkbox field and in the div say data added
    },"json");
     } 
</script>

In the above code after getting the response from the server onselect() ,how to say "data added" in the status div for selected checkbox only

A: 

to display in div use html() func

$('#statusdivid').html('data added');

to disable use attr()

$('#checkboxid').attr('disabled', true);
Haim Evgi
Good code but I prefer using a css class. This would be much cleaner: $('#checkboxid').addClass('disabled');
Yves M.
Thanks..But how to add the message only for selected check box
Hulk
look at jeff answer
Haim Evgi
+2  A: 

@Haim's code works but I think he was asking how to add the html to the div based on which checkbox was checked and based on the html he provided, which doesn't have specific ID's for the divs, so here is some jquery code that works with the html you have provided. It grabs the checked boxes and disables them, then grabs the next sibling div with name=status to add the html text to it.

$('input:checkbox:checked').attr('disabled', true);
$('input:checkbox:checked + div[name=status]').html('data added');

You can see a jsFiddle page with an example with your HTML (without the Ajax part and just done in the click event of the button instead).

Jeff T
+1 you right i dont understand the question properly
Haim Evgi
JsFiddle page was helpful..Thanks
Hulk