Jump to content

This doesnt work on Chrome


Shadowing

Recommended Posts

Hey guys im having issues getting this to work in chrome. It works in opera,IE8 and firefox Im not sure if its the onfocus thats not working or the preventdefaultnot sure how to problem solve it to figure out which to help narrow it down whats happening is when the link is clicked it refreshes the page

<a id='210235' href='' onfocus='planet_details(210235)'>test</a>

function planet_details(address){  $("a#"+address).click(function(event) {    event.preventDefault();$.ajax({		     url: "/ajax/map.php?functions=popup",		     type: 'POST',		     dataType: 'json',		     data: {  	address: address   },		  	success: function(response) {				 $('.planet_info').html(response.details);		  	}});});}

Edited by Shadowing
Link to comment
Share on other sites

Maybe Chrome changes the page before the event gets to fire. Prevent the page from changing by returning false to an onclick event handler.

Link to comment
Share on other sites

thanks for the reply Ingolme you mean like this

$("#"+address).click(function() {  //event.preventDefault();return false;}); 

shouldnt this still work though? just onfocus with alert

<a id='210235' onfocus='alert("onfocus is working")' href='' >test</a>
Edited by Shadowing
Link to comment
Share on other sites

wouldn't it be better to give all the specific anchor links a class name, check if clicked, prevent page reload, retrieve id ref, call function with id ref

$(".whatever").click(function(event) {event.preventDefault();planet_details($(this).attr("id"));});  function planet_details(address){  $.ajax({                     url: "/ajax/map.php?functions=popup",                     type: 'POST',                     dataType: 'json',                 data: {          address: address   },                     success: function(response) {                            $('.planet_info').html(response.details);                          }});}

<a class="whatever" id='210235' href=''>test</a>

Link to comment
Share on other sites

yah someone mention this to me before but I didnt know how to turn the id into a variable like you just did above oh so i give all links the same class name? then if any of the links with that class name is click it grags the id from that link? I'll try this out, cause yah this would be way better specially for future projects that will be much more advance maps.

Link to comment
Share on other sites

Alright I attempted this route. I dont understand this line of code below.

planet_details($(this).attr("id"));

im grabing the number I assigned to the id right? so I need it to be a variable so i can pass it through the planet_details function anyways i couldnt get this to pop the alert up wierdive used click a ton of times with no issues

<img id='$address' class='whatever' onmouseover='popup(\"$picture\")' src='images/star.jpg'> $(function(){$(".whatever").click(function(event) {  event.preventDefault();  alert("working"); });});

Edited by Shadowing
Link to comment
Share on other sites

when i put the html directly on the page it works so the problem is caused from ajax placing the html on the page and for some reason jquery cant read it. the jquery code is directly on the page and placed after the function that places the images on the page

Link to comment
Share on other sites

On the bright side. the code works other then that lol Oh i just realized something lol I see what this line is doing now

planet_details($(this).attr("id"));

I didnt notice the 2nd set of () lolso you are calling the function there and passing the variable at once my bad lol Alright so now i just have to figure out why i cant read html being placed on the page with an ajax script

Edited by Shadowing
Link to comment
Share on other sites

The click function is applied to all element with specific ref on load of the page, so any element with the same reference added AFTERWARDS does not have this function assigned to them, Luckily Jquery came up with live()

$(".whatever").live('click' ,function(event) {event.preventDefault();planet_details($(this).attr("id"));}); 

Link to comment
Share on other sites

geez no idea why i cant read the html that is being inserting with ajax onto my page.I problem solved it down to a dead end road lol. This sucks to cause this new method is so much better. i have java script function "arrows" on the page excuting the function from a external java script page that is linked in the header of the page.

<script type="text/javascript" src="<?php echo LPATH; ?>jquery/map.js"></script> // this contains arrows function arrows(); // activating the arrows function

arrows does a ajax call and inserts link/image onto the page

$map_array .= "<a class='whatever' href='project.php'><img src='images/star.jpg' ></a>";

inserts it into the div with the class name "map"

$('div.map').html(response.display_stars);

and this below thinks that the image/link with the class name "whatever" doesnt exist

$(".whatever").click(function(event) {  event.preventDefault();  planet_details($(this).attr("id"));  });    function planet_details(address){$.ajax({		     url: "/ajax/map.php?functions=popup",		     type: 'POST',		     dataType: 'json',		     data: {  	address: address   },		  	success: function(response) {				 $('.planet_info').html(response.details);		  	}});}

any ideas on what i can do to help problem solve this? Firebug shows it existingthis is driving me insane. real important i figure this one out. This will change how i do things in the future EDIT: posted this before reading your reply

Edited by Shadowing
Link to comment
Share on other sites

OMG!!! it works now. that makes sense onclick only assigns its self to stuff on page load. Geez thank you so much, this is much better way of doing things. going to try to see if i can make it work with the onmouseover function im using instead of using onmouseover need to find out jqueries subsitute for using onmouseover

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...