RisingSun
RisingSun

Reputation: 1733

onclick on image is not working

I am trying to display some info when a user clicks on an image. Here is the image tag

<img src="<? echo $list[image]; ?>" onclick="showUser(<?php echo $list['id']; ?>)">

I am directly using the example from w3schools. Here is the link

Is there something i am doing wrong? When I click the image nothing happens.

Upvotes: 0

Views: 191

Answers (2)

RisingSun
RisingSun

Reputation: 1733

I figured out the problem myself. In my showUsers function when I call xmlHttp.open I had the path to my file wrong. Thanks anyway

Upvotes: 0

I don't recommend using that GET method, it would be better to use a load method instead because you would have less code to work with and in my opinion it would make things easier. Now here's how I would do it. Assuming you got that code from there, this is what you can do:

<script type="text/javascript">
ShowUser(str) {$(function) {
  $('#loadhere').load("thepagetoloadfrom.php?q="+str);
}};
</script>

#loadhere is where you want to load the output from the load(). This is much shorter and easier to understand I believe.

Upvotes: 1

Related Questions