0

Hi I am using codeigniter for this project

I have a button element as below

<div class=" pull-right" id="container">
    <button class="btn btn-info">
       <a style="text-decoration:none;color:white" href="">Guide</a>
    </button>
</div>

This button element is part of a div which is one of the results from the search. When I click on the button, how do i pass the information of the div to the controller I want? The information I want to pass is just the element id of the div which is "container".

3
  • 1
    So wheres the ID of the element? what element you talk about? the button? Commented Jul 10, 2012 at 13:45
  • sorry as edited above. id of the div which is "container" Commented Jul 10, 2012 at 13:53
  • I'll update my answer to use javascript ... Commented Jul 10, 2012 at 14:12

2 Answers 2

1

Try do like that

<button class="btn btn-info">
   <a style="text-decoration:none;color:white" href="control/method/value">Guide</a>
</button>

In your class can do like that

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Control extends CI_Controller {

    public function method($value) {
        // Your value is in $value;
    }

}

[Update] Getting the parent ID element dynamically

<div class=" pull-right" id="container">
    <button class="btn btn-info" onclick="window.location='/controller/method/' + this.parentNode.id;">
       <a style="text-decoration:none;color:white">Guide</a>
    </button>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Thats the one I need!
1

Using jQuery:

$('.btn').click(function () {
    $.ajax({
        type : "POST",
        url : 'controller/method',
        data: {id : $(this).parent().attr('id')},
        success : function(data) {}
    });
});

In your controller:

$id = $this->input->post('id', TRUE);

1 Comment

@edelweiss Why that's is correct? I've created exactly what you asked.

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.