Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Sim
    Sim is offline
    New Coder
    Join Date
    Feb 2009
    Posts
    81
    Thanks
    1
    Thanked 1 Time in 1 Post

    jQuery (only first link is jquerying?)

    Heres my HTML without the JS includes. I got included the latest jquery.min.1.8 or whatever and my own js file which is shown below

    the problem is it only works with the Baltimore location and not New York? Why? If its because of a conflicting name issue, anyone got a simple work-a-round because I will be adding a ton more locations.


    Code:
    <a href="#" name="loc" id="loc" src="index.php?where=location&id=2">Baltimore</a><br>
    								<a href="#" name="loc" id="loc" src="index.php?where=location&id=1">New York</a><br>

    heres my JS file:

    Code:
    $(document).ready(function(){			
    	$("#loc").mouseup(function () {
    			alert($("#loc").attr("src"));
    
    		$.ajax({
    		      url: $("#loc").attr("src"),
    		      global: false,
    		      type: "POST",
    		      data: $("#form1").serialize(),
    		      dataType: "html",
    		      success: function(msg){     		         
    		      	 $("#right_col").html(msg);		         
    		      },
    		      error: function(msg) {
    		      	$("#right_col").html(msg);
    		      }
       		});
    	});
    });
    Online RPG Creator - Create Your Own Online RPG with no programming knoweldge

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    You are using the same ID for both anchors. You can only have one id with a given name.
    id="loc" will only get the first <a> recognized.

    the scr attribute does not belong in a <a> tag. It throws up errors and will get you into trouble.

    Here's an easy way to do what you want [the ajax has not been checked, it don't look like it works]:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    Call your javascript jquery library here
    <script type="text/javascript">
    function anchor_ajax(place){
    	$.ajax({
    		url: place,
    		global: false,
    		type: "POST",
    		data: $("#form1").serialize(),
    		dataType: "html",
    		success: function(msg){
    		 $("#right_col").html(msg);
    		},
    		error: function(msg) {
    		$("#right_col").html(msg);
    		}
    	});
    }
    </script>
    </head>
    
    <body>
    <a href="" class="loc" onclick="anchor_ajax('index.php?where=location&id=2');">Baltimore</a><br />
    <a href="" class="loc" onclick="anchor_ajax('index.php?where=location&id=1');" >New York</a><br />
    
    </body>
    </html>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •