1

Ok, I manage somehow to get value of checkbox, but now i have another issue.

This is my view, rssFeeds.php

<?php foreach( $feeds as $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 are my feeds....
    </div>
</div>
<?php endforeach; ?>

I have this script, which take checkbox value, and send it to my 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) 
          {
              // what should i do here ?....
          }
      })
    });
  });
</script>

In my controller, i just load a model which change a value on my database, 0 or 1( meaning read or unread).

The problem is that nothing change on my table... I need to put something in that .succes function in ajax ? What.. ? I just need to change one value in my database....

5
  • name="checkbox[<?=$row->id?>]" then you can look for $_POST['checkbox'] and foreach it... Commented Oct 29, 2014 at 16:04
  • I just update my question. I really need your help with this issue... Commented Oct 31, 2014 at 12:40
  • You need to regenerate the table, you can destroy it, or update it via JS/jQuery Commented Oct 31, 2014 at 12:43
  • So it cannot be done with codeigniter, using model ?...How i do that from js/jquery....can you help me a little, please?.. Commented Oct 31, 2014 at 12:56
  • Codeigniter is just the backend, it has nothing to do with the front end scripts (in terms of live updates) - You need to use ID's and utilise jQuery to update the page content. Commented Oct 31, 2014 at 13:24

1 Answer 1

3

@James-Lalor has the answer you are looking for, but I'll expand upon it.

You can give inputs the same name (radio buttons, checkboxes) to have them interact with each other. In the case of radio buttons it's actually required to have the same name to mark and unmark others. However in this case we will use <input name=example[]> note the [], this means when you do an ajax post (or any post) it will send all the values checked as an array.

So following James' suggestion, you would do a <input name="checkbox[<?php echo $row->id?>]" to which you can post using $.post(url, data, callback), the easiest way to do this would be to put it into a form, assign the form an id, do a serialized post. You could do something 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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.