Jump to content

Recommended Posts

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?

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...

 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()

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...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.