Saturday 15 September 2012

javascript - CodeIgniter PHP: change value in database when checkbox is mark/unmark -



javascript - CodeIgniter PHP: change value in database when checkbox is mark/unmark -

ok, manage somehow value of checkbox, have issue.

this view, rssfeeds.php

<?php foreach( $feeds $row ) : ?> <div class="row"> <div class="col-md-2 col-sm-3 text-center"> <a class="story-title"><img alt="" src="http://www.solostream.com/wp-content/uploads/2014/06/20140110080918_0555.jpg" style="width:100px;height:100px"></a> <label class="checkbox-inline"> <input type="checkbox" class="chkbox" value="chkbox_<?php echo $row->category; ?>_<?php echo $row->id; ?>"> mark read </label> </div> <div clas="col-md-10 col-sm-9"> // here feeds.... </div> </div> <?php endforeach; ?>

i have script, take checkbox value, , send controller:

<script> $(document).ready(function(){ $(document).on('click','.chkbox',function(){ var id=this.value; $.ajax( { type: "post", context: "application/json", data: {id:id}, url: "<?php echo site_url('rssfeedreader/markreadunread'); ?>", success: function(msg) { // should here ?.... } }) }); }); </script>

in controller, load model alter value on database, 0 or 1( meaning read or unread).

the problem nil alter on table... need set in .succes function in ajax ? what.. ? need alter 1 value in database....

@james-lalor has reply looking for, i'll expand upon it.

you can give inputs same name (radio buttons, checkboxes) have them interact each other. in case of radio buttons it's required have same name mark , unmark others. in case utilize <input name=example[]> note [], means when ajax post (or post) send values checked array.

so next james' suggestion, <input name="checkbox[<?php echo $row->id?>]" can post using $.post(url, data, callback), easiest way set form, assign form id, serialized post. like:

<form id="rss_form" method="post" action="javascript:rssupdate();"> <input name="checkbox[<?php echo $row->id?>]" type="checkbox"/> <input type="submit" value="submit"/> </form> <script> function rssupdate() { $.post(url/to/post/to, $("#rss_form").serialize()); } </script>

javascript php mysql ajax codeigniter

No comments:

Post a Comment