[Javascript] peculiarity of onselectstart

David T. Lovering dlovering at gazos.com
Sun Jul 13 10:32:04 CDT 2003


I just noticed in passing a peculiarity of "onselectstart" which is somewhat annoying.

What I want to be able to do is eliminate drag-selection of multiple fields, blank form background, etc. by an
inadvertant swipe of the mouse while the select button is depressed, while at the same time still permitting
drag-selection of the contents of single fields.  Ostensibly this model should work:

	<html>
    <head>
      <title> bogus </title>
      <script language='JavaScript'>
      <!--
        document.onselectstart = disableSelect;
        function disableSelect { return false; }
        function enableSelect { return true; }
      // -->
      </script>
    </head>
    <body>
      <form name='myBogusForm' action='javascript:void(null)'>
        <center>
          <input name='field1' type='text' value='' size=30 onselectstart='enableSelect'><br>
          <input name='field2' type='text' value='' size=30 onselectstart='enableSelect'><br>
        </center>
      </form>
    </body>
    </html>

Sadly, the 'document.onselectstart' declaration appears to take precedence over all the fields, irrespective of whether they have localized onselectstart declarations of their own.  Yes, I've tried using straight 'return true' declarations in lieu of
'enableSelect' function calls.  Still no cigar.

Anybody have any ideas?  This one has me stumped.

-- Dave Lovering


More information about the Javascript mailing list