Thanks for the help.

I do not really want to use an inline onclick, but I am a javascript
newbie, and I was unsure how to still pass the two variable to the
function if I did not do it inline.  How could I rewrite this so that
my function will still work, but "re-factoring" as you say?

On Jul 18, 10:14 am, Mike Alsup <[EMAIL PROTECTED]> wrote:
> On Jul 18, 12:58 pm, hubbs <[EMAIL PROTECTED]> wrote:
>
>
>
> > I might be getting confused about the proper use of "this".  I thought
> > I understood how this worked, and that since I am triggering the
> > onclick even on an anchor, that the "this" would be in the context of
> > that anchor tag, so that I could grab its href.
>
> > Here is what I have done, but it is returning undefined for asseturl.
>
> > function deleteAjaxAsset(message, assetid) {
> >    var asseturl = $(this).attr("href");
> >    alert(asseturl);
> >    var confirmDelete = confirm(message);
> >    if (confirmDelete == true) {
> >       if(action == "delete") {
> >          $.ajax( {
> >             type : "POST", url : asseturl + "?action=delete" }
> >          );
> >          }
> >       }
> >    }
>
> > <a href="http://www.testpage.com"; onclick="deleteAjaxAsset('Are you
> > sure you want to delete?','testid'); return false;">Delete</a>
>
> > Thanks guys!
>
> Since you're bypassing jQuery's event framework 'this' is not
> automatically set to the anchor for you.  You'd be better off dropping
> the inline onclick attributes and doing something like this:
>
> $('a').click(deleteAjaxAsset)
>
> and refactoring deleteAjaxAsset a bit to get the args via 'this'.
>
> But you could continue using onclick if you must; I think this should
> work:
>
> onclick="deleteAjaxAsset.call(this, 'Are you sure you want to
> delete?','testid'); return false;"

Reply via email to