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 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sending data about "this"

    I need a link to execute a JS command (cmd()). How do I send the "this.href" of the "a" tag to the command and then execute according to that info?

  • #2
    New Coder
    Join Date
    Jun 2002
    Location
    yorkshire, uk
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you mean this kind of thing?

    Code:
    <script>
    function blah(url){
      alert(url) //or whatever
    }
    </script>
    
    <a href="page.html" onclick="blah(this.href)">
    neil.c

  • #3
    New Coder
    Join Date
    Jul 2002
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by neil.c
    you mean this kind of thing?

    Code:
    <script>
    function blah(url){
      alert(url) //or whatever
    }
    </script>
    
    <a href="page.html" onclick="blah(this.href)">
    But how do you define "this.href" as "url"?

  • #4
    New Coder
    Join Date
    Jun 2002
    Location
    yorkshire, uk
    Posts
    65
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by Kevlar

    But how do you define "this.href" as "url"?
    the function blah() has a new variable name (url) in its brackets. this means that whenever you call blah(), whatever you put into the brackets gets put into the url variable. in this case, it is this.href, i.e. the href of the link.
    neil.c


  •  

    Posting Permissions

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