Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. My First Post Of Shame - ReturnFalse()?

My First Post Of Shame - ReturnFalse()?

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascriptquestion
12 Posts 6 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A AspDotNetDev

    The shame is not what you think it is. They are assigning a function to a click event. This function returns false. In JavaScript, this prevents the event from doing what it does by default. So, if you have:

    <a href="#">Click Me</a>

    And you assign the ReturnFalse function to it, clicking it will not append "#" to the URL. Without assigning that click handler, it would append that to the URL. The shame is that they don't attach the event and that they compare the event to the function. They should avoid comparing completely, and they should use something like jQuery's $.bind function to add the function as a handler. Assigning a function to an event will replace all existing handlers, which should be avoided. However, if they wan't to remove all existing handlers, that may be the ideal approach.

    Thou mewling ill-breeding pignut!

    T Offline
    T Offline
    techie007
    wrote on last edited by
    #3

    Ahhh OK.... So because they are assigning it to an OnClick event, then it needs to be a function instead of just a simple Boolean, and they're trying to have the click do 'nothing', but do this to avoid having the #, instead of just assigning the OnClick to null, or removing the OnClick attribute completely? Weird... But good to know for sure... Better I learn this trick, than lose faith in the darned supplier I guess. ;)

    A 1 Reply Last reply
    0
    • T techie007

      Ahhh OK.... So because they are assigning it to an OnClick event, then it needs to be a function instead of just a simple Boolean, and they're trying to have the click do 'nothing', but do this to avoid having the #, instead of just assigning the OnClick to null, or removing the OnClick attribute completely? Weird... But good to know for sure... Better I learn this trick, than lose faith in the darned supplier I guess. ;)

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #4

      That is one confusing sentence, but I think you've got the basic idea.

      Thou mewling ill-breeding pignut!

      T 1 Reply Last reply
      0
      • A AspDotNetDev

        That is one confusing sentence, but I think you've got the basic idea.

        Thou mewling ill-breeding pignut!

        T Offline
        T Offline
        techie007
        wrote on last edited by
        #5

        The good news is it makes more sense in my brain then in my typing. :) I guess the Shame is on me in this case. ;) Regardless, CP kicks butt at teaching once again, thanks! :)

        1 Reply Last reply
        0
        • A AspDotNetDev

          The shame is not what you think it is. They are assigning a function to a click event. This function returns false. In JavaScript, this prevents the event from doing what it does by default. So, if you have:

          <a href="#">Click Me</a>

          And you assign the ReturnFalse function to it, clicking it will not append "#" to the URL. Without assigning that click handler, it would append that to the URL. The shame is that they don't attach the event and that they compare the event to the function. They should avoid comparing completely, and they should use something like jQuery's $.bind function to add the function as a handler. Assigning a function to an event will replace all existing handlers, which should be avoided. However, if they wan't to remove all existing handlers, that may be the ideal approach.

          Thou mewling ill-breeding pignut!

          M Offline
          M Offline
          Mohibur Rashid
          wrote on last edited by
          #6

          I agree with you. But yet this will do too

          Click Me

          no need to define and entire function hahaha

          A 1 Reply Last reply
          0
          • M Mohibur Rashid

            I agree with you. But yet this will do too

            Click Me

            no need to define and entire function hahaha

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #7

            Depends on if you want to dynamically toggle the functionality. And there are benefits to keeping your markup clean from inline JavaScript. Also, "önclick" will probably not work. :)

            Thou mewling ill-breeding pignut!

            M L 2 Replies Last reply
            0
            • A AspDotNetDev

              Depends on if you want to dynamically toggle the functionality. And there are benefits to keeping your markup clean from inline JavaScript. Also, "önclick" will probably not work. :)

              Thou mewling ill-breeding pignut!

              M Offline
              M Offline
              Mohibur Rashid
              wrote on last edited by
              #8

              it wont work, i wonder how i wrote that character?

              A 1 Reply Last reply
              0
              • M Mohibur Rashid

                it wont work, i wonder how i wrote that character?

                A Offline
                A Offline
                AspDotNetDev
                wrote on last edited by
                #9

                If you are using a "US - International" keyboard layout, you can type that character by typing a quote mark followed by the letter "o".

                Thou mewling ill-breeding pignut!

                1 Reply Last reply
                0
                • A AspDotNetDev

                  Depends on if you want to dynamically toggle the functionality. And there are benefits to keeping your markup clean from inline JavaScript. Also, "önclick" will probably not work. :)

                  Thou mewling ill-breeding pignut!

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #10

                  Önclick? That definitely sounds Turkish :)

                  I'm invincible, I can't be vinced

                  O 1 Reply Last reply
                  0
                  • L Lost User

                    Önclick? That definitely sounds Turkish :)

                    I'm invincible, I can't be vinced

                    O Offline
                    O Offline
                    Orcun Iyigun
                    wrote on last edited by
                    #11

                    because i am Turkish I get it :)

                    1 Reply Last reply
                    0
                    • A AspDotNetDev

                      The shame is not what you think it is. They are assigning a function to a click event. This function returns false. In JavaScript, this prevents the event from doing what it does by default. So, if you have:

                      <a href="#">Click Me</a>

                      And you assign the ReturnFalse function to it, clicking it will not append "#" to the URL. Without assigning that click handler, it would append that to the URL. The shame is that they don't attach the event and that they compare the event to the function. They should avoid comparing completely, and they should use something like jQuery's $.bind function to add the function as a handler. Assigning a function to an event will replace all existing handlers, which should be avoided. However, if they wan't to remove all existing handlers, that may be the ideal approach.

                      Thou mewling ill-breeding pignut!

                      K Offline
                      K Offline
                      Kieryn Phipps
                      wrote on last edited by
                      #12

                      I think it would be less misleading if the ReturnFalse function was instead named AbortAction or something closer to the intention. I think it is better practise to name a function or method for it's intended purpose or meaning than for what it literally does. The intention/meaning and what the method actually does usually are the same, but there can be subtle differences and occasionally vast differences such as in this case. Oh and a comment for the function would not go amiss either:

                      //This function is used to suppress events such as onclick
                      function AbortAction()
                      {
                      return false;
                      }

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups