[Javascript] peculiarity of onselectstart/third

David Lovering dlovering at gazos.com
Wed Jul 16 15:50:25 CDT 2003


Just to wrap up this discussion, I polished Bekim's code to "full workability" and am including it below.  Rather than prescribing naming conventions for active fields (who wants all their active inputs to be called "field-XXX"?), I modified the routine to work off the nodeName and type, thusly:

  function handleSelectStart(evt) {
    evt = (evt) ? evt : (window.event) ? window.event : "";
    if (evt) {
      var inputType = evt.srcElement.type;
      var inputNodeName = evt.srcElement.nodeName;
      if (inputNodeName == "INPUT") {
        return true;
      }
      if (inputNodeName == "TEXTAREA") {
        return true;
      }
      if (inputType == "undefined") {
        return false;
      }
      return false;
    }
  } // handleSelectStart()

  document.onselectstart = handleSelectStart;

Note -- certain older versions of Netscape may have issues with the handler name, as they generally prefer all lower-case for such things.

Anyway, this method worked like a champ on the four or five browser types I had time to check.  Thanks Bekim!

Now if only someone could explain to me why the various major browser-writing bodies didn't build this into their engines at the get-go, I'd be a happy man.

-- Dave Lovering
  ----- Original Message ----- 
  From: BEKIM BACAJ 
  To: javascript at LaTech.edu 
  Sent: Wednesday, July 16, 2003 11:12 AM
  Subject: Re: [Javascript] peculiarity of onselectstart/third


  Well, you owe me this one! 
  the onselectstart turned false disables all the content from being 
  selected, no matter what you do after this will not help so wei will 
  filter unwanted items like this: 
  <HTML>
      <HEAD>
        <TITLE> Trojani </TITLE>
        <script language='JavaScript'>
        <!--

  function filterSelectability(){
    var inptName=event.srcElement.name;
  //Headache! - suppressing error for "undefined" elements 
   if (typeof(inptName) == "undefined"){return false}
    var fld=inptName.substring(0,5);
   if(fld=='field'){return true}
        else{return false}
    }
          document.onselectstart = filterSelectability;
        // -->
        </script>
      </head>
      <body>

        <form name='myBogusForm' action='javascript:void(null)'>
          <center>

            <input name='field1' type='text' value='' size=30 ><br>
            <input name='field2' type='text' value='' size=30 ><br>

          </center>
        </form>

      </body>
  </html>
   

  Had some hard time with undefined items but it is solved now, 
  Cheers! 



------------------------------------------------------------------------------
  Protect your PC - Click here for McAfee.com VirusScan Online 


------------------------------------------------------------------------------


  _______________________________________________
  Javascript mailing list
  Javascript at LaTech.edu
  https://lists.LaTech.edu/mailman/listinfo/javascript

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20030716/d88b11c8/attachment.htm>


More information about the Javascript mailing list