CodeIgniter Forums
How to show something on the right from a link on the left using Ajax - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to show something on the right from a link on the left using Ajax (/showthread.php?tid=43100)

Pages: 1 2


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]the_unforgiven[/eluser]
Hi Guys,

Just wondering what's the best way to show something from a link

Basically I have a list of links on the left of my page and when a link is clicked I want the info to show on the right of the same page so you are never leaving the page you are currently on.

And this only needs to display when the link is clicked otherwise it will show some hmtl text i will place there.

Can someone point me in the right direction has to what is the best way to do this and I'm a noobie at Ajax so be gentle.


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]marjune[/eluser]
what i did in something like this is division for the menu and another division to where you show some stuff if the menu was clicked!!


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]the_unforgiven[/eluser]
What lines of code would i write in order to make the div appear once the link is clicked?


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]marjune[/eluser]
somethig like this

Code:
[removed]
  
$(function(){
  
   $('#menuone').click(function(){
      
      $('#display').load("<?php print base_url().'index.php/yourcontroller/controllerfunction'?>");

   });

});

[removed]

<a href = "#" id = "menuone">menu</a>


<div id = "display">


</div>



How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]the_unforgiven[/eluser]
Ok great i'll try that then


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]the_unforgiven[/eluser]
That works but am using a foreach statement and its getting the id but it';s showing all data from DB

Code:
<div id="events" class="scroll-pane">

    &lt;?php
    $query = $this->db->query('SELECT * FROM mcd_events');

    foreach ($query->result() as $row)
    {
    
    ?&gt;
        <h3>Date:&lt;?php echo date("F j, Y",strtotime($row->created_on)) ?&gt;</h3>
        
        <p><br /><a >id ?&gt;" id="linkid">&lt;?php echo $row->title ?&gt;</a></p>
        
    &lt;?php } ?&gt;

</div>
</div>
&lt;!-- content left --&gt;

&lt;!-- content right --&gt;
<div id="content-right">
    
    <h2>Events/Rideouts</h2>
    
    <div id="display">
    &lt;?php
    $query = $this->db->query("SELECT * FROM mcd_events ");

    foreach ($query->result() as $row)
    {
    
    ?&gt;
        <p>&lt;?php echo $row->description ?&gt;</a></p>
        
    &lt;?php } ?&gt;
    </div>
    <div class="clear"></div>
</div>



How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]marjune[/eluser]
your view in <div id="display"> </div> must in other file then your just calling it and load it in the <div id="content-right"></div>


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]the_unforgiven[/eluser]
Code:
<div id="display">
&lt;?php
    $query = $this->db->query("SELECT * FROM mcd_events ");

    foreach ($query->result() as $row)
    {
    
    ?&gt;
        <p>&lt;?php echo $row->description ?&gt;</a></p>
        
    &lt;?php } ?&gt;
    </div>

This is in the view folder, inside display div which is inside content-right div


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]marjune[/eluser]
and that must the other view file then just load it in the controller.


How to show something on the right from a link on the left using Ajax - El Forum - 06-30-2011

[eluser]the_unforgiven[/eluser]
Sorry I dont understand that doesn't make sense