0

I am in a little bit of a predicament. I am writing a programme where a user can make a search. Then the search returns a possible list of results. If you move your mouse over the results it highlights them. When you select one of the items from the result, it replaces the list with the item you selected. The problem I am having is that I can't get the item to replace the list. I am using CodeIgniter.

Steps

In my model, I pass the id (VenueID) of item through onclick function to my javascript function.

venue_model.php:

$output .= '<li><a href="#self" class="menulink" class=&{ns4class};
               onClick="changeDiv(\''.
                 $venue_details->**VenueID**.

               '\')">

The javascript function takes the javascript id and then passes it to a function in the controller to retrieve the item from a MySQL database.

divUpdater.php:

<script type="text/javascript">
base_url = '<?= base_url();?>index.php/';
</script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">

function changeDiv(venueID){
  $.get(base_url+'home/get_venue_description/' + venueID , function(data) {
    $('#venue_description').html(data);
    document.getElementById('venue_description').innerHTML=data;
  });

}

here is the function from the controller that retrieves the data from the database

home.php (controller)

    function get_venue_description($venueID){
       echo $this->venue_model->retrieveData($venueID);
      }

The problem is in the model and the divUpdater.php. When I click on one of the item from the list, it gives me this url

http://localhost/Counter/index.php#self

And this is becasue of the anchor tag in the model (<a href="#self"...). I was wondering if it was possible to get the code in the divUpdater.php to execute and retrieve the data in the background without having the url change.

Please does anyone know how to do that?

6
  • possible duplicate of Troubles using jquery get to retrieve data from the server and place in a div Commented Nov 7, 2010 at 18:47
  • 1
    you can't access mysql database from JS. Lack of understanding is your real trouble Commented Nov 7, 2010 at 18:49
  • I am new to this. What do u suggest? Commented Nov 7, 2010 at 19:37
  • I am using the controller to get access to the database. Is there an alternative way of doing what I am doing? Commented Nov 7, 2010 at 19:42
  • 1
    This might sound pedantic, but my first suggestion is to write proper English in your post. Reading it as it was would probably turn a lot of people away from this question. Secondly, begin to accept answers for your questions, and perhaps you will get more replies. Commented Nov 7, 2010 at 21:47

1 Answer 1

1

If you do not want the default click behavior of a link to occur (going to #self when clicking a link with href="#self"), then your onclick handler should return false.

onClick="changeDiv(stuff); return false;"

I don't know if that will help with anything else.

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.