kthxbai2u Posted June 19, 2009 Share Posted June 19, 2009 Ok, I am not a JavaScript programmer, although I have been picking alot of things up... I am using PHP, and Ajax right now, and I am working on a menu. I am trying to assign a custom value to the <.a.> tag like <a href='ignorethefile.php' myattribute='page_location'> and then retrieve it within JScript, and pass it through a wack load of functions that dont have names... Assume the onclick calls this function below already function clickMenuLink() { var LoadMsg = 'Loading Content...'; disableMenuLinks(); if(!$(this).hasClass("current")) { var _Href = $(this).attr('href'); var pg = $(this).attr('myattribute'); $("<div id='loading'> "+LoadMsg+' </div>').appendTo('body').fadeIn('slow',function(pg){ $.ajax({ type: 'POST', url: "/tempsite/index.php/" + pg + "/", data: "ajax=1&nohref=1", dataType: 'html', timeout: 5000, success: function(d,s,pg){ $('#loading').fadeOut('slow',function(){ $(this).remove(); $('#main').slideUp('slow',function(){ $(this).html(d).slideDown('slow'); ajaxifyContentLinks(); enableMenuLinks(pg); }); }); }, error: function(o,s,e){ window.location = _Href; } }); } ); } return false; } but it seems that the value is not being retrieved from the A tag.... Anyone know what I did wrong? Quote Link to comment Share on other sites More sharing options...
MadTechie Posted June 19, 2009 Share Posted June 19, 2009 shouldn't url: "/tempsite/index.php/" + pg + "/", be url: "/tempsite/index.php?pg=/" + pg + "/", or if the PHP uses the POST then pg should be in data ie data: "ajax=1&nohref=1&pg="+pg, Quote Link to comment Share on other sites More sharing options...
kthxbai2u Posted June 19, 2009 Author Share Posted June 19, 2009 Oh sorry, i neglected to mention I am using CodeIgniter..... That is a url to send the browser to after getting the custom attribute. My only concern is that I cant get that custom attribute... That attribute defines the page name... Quote Link to comment Share on other sites More sharing options...
kthxbai2u Posted June 19, 2009 Author Share Posted June 19, 2009 var pg = $(this).attr('myattribute'); dont even get my attribute... Anyone know how to do this? I have been googling all day on this one thing... I even tried changing myattribute to id and then tried $(this).id and $(this).attr('id') nothing works... I been getting "undefined" when i pipe that to alertbox() Quote Link to comment Share on other sites More sharing options...
MadTechie Posted June 19, 2009 Share Posted June 19, 2009 Personally i use document.getElementsByID('test').getAttribute('myattribute'); so try var pg = $(this).getAttribute('myattribute'); Quote Link to comment Share on other sites More sharing options...
kthxbai2u Posted June 20, 2009 Author Share Posted June 20, 2009 Personally i use document.getElementsByID('test').getAttribute('myattribute'); so try var pg = $(this).getAttribute('myattribute'); I tried $(this).getAttribute('myattribute'); but it returns undefined... And I am trying to get the ID, or the custom attribute... I dont know what the ID is unless I use $(this).id or whatever you use to get the id... Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted June 20, 2009 Share Posted June 20, 2009 Is that a stand alone function? If so, then $(this) wouldn't reference anything. What's $(this) supposed to be in your case? Change it to whatever element it's supposed to be. Quote Link to comment Share on other sites More sharing options...
kthxbai2u Posted June 25, 2009 Author Share Posted June 25, 2009 Sorry, been away... I think the problem is that $(this) used to reference the link that was clicked.,... This is within an onclick event for the link.... Doesn't the event handler pass in the object that called it? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.