Let-click send to need right?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • George Hester

    Let-click send to need right?

    In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to get the focus no matter where on the page the user clicks be it right-click or left-click. Right now there is no context menu when the user right-clicks. Do you think that's the problem? Any ideas how to get this right-click left-click Input box get's focus with JavaScript? Thanks.

    Here's what I have so far:

    <script type="text/javascript" for="document" event="onclick" >
    <!-- Begin
    //window.event.sr cElement.cancel Bubble = true;
    //window.event.re turnValue = true;
    if (frm1.UID.value == ''){
    document.frm1.U ID.focus();
    }
    // End -->
    </script>

    The UID is the ID for the Input box; frm1 is the name of the Form; this script resides within the <HEAD> tag.

    --
    George Hester
    _______________ _______________ ____
  • Matthew Warden

    #2
    Re: Let-click send to need right?

    On 12/28/03 1:33 AM, in article BOuHb.84420$JW3 .62215@twister. nyroc.rr.com,
    "George Hester" <hesterloli@hot mail.com> wrote:
    [color=blue]
    > In a page I have when the user left-clicks the page a Input box for a form
    > gets the focus. But if the user right-clicks the page the Input box is not
    > getting the focus. I'd like the Input box to get the focus no matter where on
    > the page the user clicks be it right-click or left-click. Right now there is
    > no context menu when the user right-clicks. Do you think that's the problem?[/color]

    Possibly. Where is the code you are using for that? If you are returning
    false to the onclick event within your no-context-menu code, then that's
    probably what's canceling the event.



    --
    mattwarden
    mattwarden.com

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Let-click send to need right?

      "George Hester" <hesterloli@hot mail.com> writes:

      (please keep your lines below ~72 characters. The following was one long
      line).
      [color=blue]
      > In a page I have when the user left-clicks the page a Input box for
      > a form gets the focus. But if the user right-clicks the page the
      > Input box is not getting the focus. I'd like the Input box to get
      > the focus no matter where on the page the user clicks be it
      > right-click or left-click.[/color]

      That could be highly annoying.

      Why do you want that? If it is to give focus to the input element when
      the user gives the browser focus, I would use the window.onfocus handler.
      [color=blue]
      > Right now there is no context menu when the user right-clicks. Do
      > you think that's the problem?[/color]

      Tampering with standard browser behavior is almost always a problem
      for the user. If I right-click, I expect the context menu to appear
      (and in my browser, it will, no matter what you try :).

      However, I can't see how your code stops the context menu. Are you
      sure the code you posted is the correct one? Can you show us a page
      that has the problem?
      [color=blue]
      > Any ideas how to get this right-click left-click Input box get's
      > focus with JavaScript?[/color]

      Let's see what you have:
      [color=blue]
      > Here's what I have so far:
      >
      > <script type="text/javascript" for="document" event="onclick" >[/color]

      So, this code is supposed to work in Internet Explorer only. The
      "for" and "event" attributes are proprietary Microsoft inventions, and
      won't work in any other browser, as is "window.eve nt". To get the
      samme effect in both IE and other browsers, I would do:

      <script type="text/javascript">
      document.onclic k = function (event) {
      event = event || window.event; // IE sucks
      /// your code, but with "event" instead of "window.eve nt".
      }
      </script>
      [color=blue]
      > <!-- Begin[/color]

      HTML-like comments are not necessary in Javascript.
      [color=blue]
      > //window.event.sr cElement.cancel Bubble = true;[/color]

      That would be
      window.event.ca ncelBubble = true;
      in IE.
      [color=blue]
      > //window.event.re turnValue = true;
      > if (frm1.UID.value == ''){[/color]

      Again, a safer, cross browser, method of referring to a form control is:
      if (document.forms['frm1'].elements['UID'].value == '') {
      Just using the form name as a global value is also IE specific.
      [color=blue]
      > document.frm1.U ID.focus();
      > }
      > // End -->
      > </script>
      >
      > The UID is the ID for the Input box; frm1 is the name of the Form;
      > this script resides within the <HEAD> tag.[/color]

      That means that the user can click the page between the time when the
      handler is assigned and the form is loaded. It is not dangerous, but
      will give a Javascript error. It would be safer to assign the handler
      after the form has been loaded.


      How I would do it:
      ---
      <script type="text/javascript">
      document.onclic k = function(event) {
      // event = event || window.event; // if you need it.
      var ctrl = document.forms['frm1'].elements['UID'];
      if (ctrl.value == "") {
      ctrl.focus();
      }
      }
      </script>
      ---
      and I would put this code right after the </form> of <form id="frm1" ...>.


      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Jim Ley

        #4
        Re: Let-click send to need right?

        On Sun, 28 Dec 2003 14:22:25 +0100, Lasse Reichstein Nielsen
        <lrn@hotpop.com > wrote:[color=blue]
        > The
        >"for" and "event" attributes are proprietary Microsoft inventions, and
        >won't work in any other browser, as is "window.eve nt". To get the
        >samme effect in both IE and other browsers, I would do:[/color]
        [color=blue]
        > event = event || window.event; // IE sucks[/color]

        If you believe this is a bad design for events in js then can you
        please tell the SVG WG, who currently have it in a draft: (evt not
        event, but that's the only difference)



        www-svg@w3.org of course.

        Jim.

        --
        comp.lang.javas cript FAQ - http://jibbering.com/faq/

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: Let-click send to need right?

          jim@jibbering.c om (Jim Ley) writes:
          [color=blue]
          > On Sun, 28 Dec 2003 14:22:25 +0100, Lasse Reichstein Nielsen
          > <lrn@hotpop.com > wrote:[/color]
          [color=blue][color=green]
          >> event = event || window.event; // IE sucks[/color]
          >
          > If you believe this is a bad design for events in js then can you
          > please tell the SVG WG, who currently have it in a draft: (evt not
          > event, but that's the only difference)[/color]

          I hadn't really thought about it, the "IE sucks" that I habitually
          add, refers to IE's lacking support for DOM 2 Events, where the event
          is passed an argument.

          Maybe a little ironic, since I assign the event handler directly to
          the "onclick" property instead of using the DOM 2 Events method
          "addEventListen er", but guess who doesn't support that either :).

          However, having thought about it for not very long, I do believe
          it is a bad design, because globally variables like that prohibits
          multithreading. While current browsers are quite singlethreaded in
          their Javascript execution, adding design that makes it impossible
          to change that is ... well, bad design.
          [color=blue]
          > http://www.w3.org/TR/SVG12/#WindowObject[/color]

          Looking a this, it seems the only use of "evt" is in HTML attributes,
          e.g.,

          <pushButton xmlns="http://bar.example.org/buttons"
          action="myCallb ack(evt)"/>

          The actual handler function then uses its argument instead of the
          global variable. I think this is using the same thinking that the
          makers of IE used: The variable must be available to event handler
          attributes, so we make it global instead of making a new one for each
          event.

          Generally, I don't like the way the SVG DOM is being made. It is not
          very progressive.
          Why call the global object "window" at all? I would much have
          preferred separate global and window objects (as I would in normal
          browsers too). They are putting too much crap into the global object.
          [color=blue]
          > www-svg@w3.org of course.[/color]

          Is what? A mailing list, a mail address for comments, or?

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • Jim Ley

            #6
            Re: Let-click send to need right?

            On Sun, 28 Dec 2003 15:00:53 +0100, Lasse Reichstein Nielsen
            <lrn@hotpop.com > wrote:
            [color=blue][color=green]
            >> http://www.w3.org/TR/SVG12/#WindowObject[/color]
            >
            >Looking a this, it seems the only use of "evt" is in HTML attributes,
            >e.g.,[/color]

            In their examples yes, but, it's still there in the IDL.
            [color=blue]
            >Generally, I don't like the way the SVG DOM is being made. It is not
            >very progressive.[/color]

            They're not really making it, they're rubber stamping and fixing the
            de-facto ones...
            [color=blue][color=green]
            >> www-svg@w3.org of course.[/color]
            >
            >Is what? A mailing list, a mail address for comments[/color]

            It's both. and I'd urge people to get involved, the W3's script
            knowledge is unfortunately not what it could ideally be.

            Jim.
            --
            comp.lang.javas cript FAQ - http://jibbering.com/faq/

            Comment

            • George Hester

              #7
              Re: Let-click send to need right?

              Actually I think I should remove the script I had to remove the context-menu. I don't think it works right. But here it is:

              <!-- Begin
              //Disable right click script III- By Muzaffer Mohammad (muzzu@muzzu.ca .tc)
              //For full source code, visit http://www.muzzu.ca.tc
              var message="";

              function clickIE(){
              if (document.all){
              (message);
              alert('message = ' + message);
              return false;
              }
              }

              function clickNS(e){
              if(document.lay ers||(document. getElementById& &!document.all) ){
              if (e.which==2||e. which==3){
              (message);
              return false;
              }
              }
              }

              if (document.layer s){
              document.captur eEvents(Event.M OUSEDOWN);
              document.onmous edown=clickNS;
              } else{
              //alert(clickIE);
              document.onmous eup=clickNS;
              document.oncont extmenu=clickIE ;
              }

              document.oncont extmenu=new Function("retur n false")

              function disableselect(e ){
              return false
              }

              function reEnable(){
              return true
              }

              //if IE4+
              document.onsele ctstart=new Function ("return false")

              //if NS6
              if (window.sidebar ){
              document.onmous edown=disablese lect;
              document.onclic k=reEnable;
              }
              // End -->

              I could just use the attribute in the Body tag:

              onContextMenu=" return false"

              and that would serve my purpose just as well. Do you think then I can capture the right-click then and if so how?

              Thanks for the reply. There is only one type of browser that will be accessing this page and that is IE from 5 on up.

              --
              George Hester
              _______________ _______________ ____
              "Matthew Warden" <newsnospam@mat twarden.com> wrote in message news:BC14044F.7 92%newsnospam@m attwarden.com.. .[color=blue]
              > On 12/28/03 1:33 AM, in article BOuHb.84420$JW3 .62215@twister. nyroc.rr.com,
              > "George Hester" <hesterloli@hot mail.com> wrote:
              > [color=green]
              > > In a page I have when the user left-clicks the page a Input box for a form
              > > gets the focus. But if the user right-clicks the page the Input box is not
              > > getting the focus. I'd like the Input box to get the focus no matter where on
              > > the page the user clicks be it right-click or left-click. Right now there is
              > > no context menu when the user right-clicks. Do you think that's the problem?[/color]
              >
              > Possibly. Where is the code you are using for that? If you are returning
              > false to the onclick event within your no-context-menu code, then that's
              > probably what's canceling the event.
              >
              >
              >
              > --
              > mattwarden
              > mattwarden.com
              >[/color]

              Comment

              • George Hester

                #8
                Re: Let-click send to need right?

                Lesse:

                'That could be highly annoying." - There is nothing else on the page so there is no reason for anything else to be done on the page except put something in the Input box. It is a logon page and the user must enter a User ID first before doing anything else except leave. Everything but that disabled at page load.

                Now I am not too concerned about making it multi-browser friendly but I will keep it in mind..

                Finally I suspect you have quite a few jewels in what you said so it'll take me some time to digest it. Thanks.

                --
                George Hester
                _______________ _______________ ____
                "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message news:pte9m60e.f sf@hotpop.com.. .[color=blue]
                > "George Hester" <hesterloli@hot mail.com> writes:
                >
                > (please keep your lines below ~72 characters. The following was one long
                > line).
                > [color=green]
                > > In a page I have when the user left-clicks the page a Input box for
                > > a form gets the focus. But if the user right-clicks the page the
                > > Input box is not getting the focus. I'd like the Input box to get
                > > the focus no matter where on the page the user clicks be it
                > > right-click or left-click. [/color]
                >
                > That could be highly annoying.
                >
                > Why do you want that? If it is to give focus to the input element when
                > the user gives the browser focus, I would use the window.onfocus handler.
                > [color=green]
                > > Right now there is no context menu when the user right-clicks. Do
                > > you think that's the problem?[/color]
                >
                > Tampering with standard browser behavior is almost always a problem
                > for the user. If I right-click, I expect the context menu to appear
                > (and in my browser, it will, no matter what you try :).
                >
                > However, I can't see how your code stops the context menu. Are you
                > sure the code you posted is the correct one? Can you show us a page
                > that has the problem?
                > [color=green]
                > > Any ideas how to get this right-click left-click Input box get's
                > > focus with JavaScript? [/color]
                >
                > Let's see what you have:
                > [color=green]
                > > Here's what I have so far:
                > >
                > > <script type="text/javascript" for="document" event="onclick" >[/color]
                >
                > So, this code is supposed to work in Internet Explorer only. The
                > "for" and "event" attributes are proprietary Microsoft inventions, and
                > won't work in any other browser, as is "window.eve nt". To get the
                > samme effect in both IE and other browsers, I would do:
                >
                > <script type="text/javascript">
                > document.onclic k = function (event) {
                > event = event || window.event; // IE sucks
                > /// your code, but with "event" instead of "window.eve nt".
                > }
                > </script>
                > [color=green]
                > > <!-- Begin[/color]
                >
                > HTML-like comments are not necessary in Javascript.
                > [color=green]
                > > //window.event.sr cElement.cancel Bubble = true;[/color]
                >
                > That would be
                > window.event.ca ncelBubble = true;
                > in IE.
                > [color=green]
                > > //window.event.re turnValue = true;
                > > if (frm1.UID.value == ''){[/color]
                >
                > Again, a safer, cross browser, method of referring to a form control is:
                > if (document.forms['frm1'].elements['UID'].value == '') {
                > Just using the form name as a global value is also IE specific.
                > [color=green]
                > > document.frm1.U ID.focus();
                > > }
                > > // End -->
                > > </script>
                > >
                > > The UID is the ID for the Input box; frm1 is the name of the Form;
                > > this script resides within the <HEAD> tag.[/color]
                >
                > That means that the user can click the page between the time when the
                > handler is assigned and the form is loaded. It is not dangerous, but
                > will give a Javascript error. It would be safer to assign the handler
                > after the form has been loaded.
                >
                >
                > How I would do it:
                > ---
                > <script type="text/javascript">
                > document.onclic k = function(event) {
                > // event = event || window.event; // if you need it.
                > var ctrl = document.forms['frm1'].elements['UID'];
                > if (ctrl.value == "") {
                > ctrl.focus();
                > }
                > }
                > </script>
                > ---
                > and I would put this code right after the </form> of <form id="frm1" ....>.
                >
                >
                > /L
                > --
                > Lasse Reichstein Nielsen - lrn@hotpop.com
                > DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                > 'Faith without judgement merely degrades the spirit divine.'[/color]

                Comment

                • George Hester

                  #9
                  Re: Let-click send to need right?

                  Hi again Lasse:

                  OK I went through what you described and can change what I have. I definitely don't want the javascript error if I can avoid it. I realize that not everyone has a "fast" connection and so yes many might get the javascript error I guess if I leave that in the <head> tag. So I moved it. Thanks for the information.

                  --
                  George Hester
                  _______________ _______________ ____
                  "Lasse Reichstein Nielsen" <lrn@hotpop.com > wrote in message news:pte9m60e.f sf@hotpop.com.. .[color=blue]
                  > "George Hester" <hesterloli@hot mail.com> writes:
                  >
                  > (please keep your lines below ~72 characters. The following was one long
                  > line).
                  > [color=green]
                  > > In a page I have when the user left-clicks the page a Input box for
                  > > a form gets the focus. But if the user right-clicks the page the
                  > > Input box is not getting the focus. I'd like the Input box to get
                  > > the focus no matter where on the page the user clicks be it
                  > > right-click or left-click. [/color]
                  >
                  > That could be highly annoying.
                  >
                  > Why do you want that? If it is to give focus to the input element when
                  > the user gives the browser focus, I would use the window.onfocus handler.
                  > [color=green]
                  > > Right now there is no context menu when the user right-clicks. Do
                  > > you think that's the problem?[/color]
                  >
                  > Tampering with standard browser behavior is almost always a problem
                  > for the user. If I right-click, I expect the context menu to appear
                  > (and in my browser, it will, no matter what you try :).
                  >
                  > However, I can't see how your code stops the context menu. Are you
                  > sure the code you posted is the correct one? Can you show us a page
                  > that has the problem?
                  > [color=green]
                  > > Any ideas how to get this right-click left-click Input box get's
                  > > focus with JavaScript? [/color]
                  >
                  > Let's see what you have:
                  > [color=green]
                  > > Here's what I have so far:
                  > >
                  > > <script type="text/javascript" for="document" event="onclick" >[/color]
                  >
                  > So, this code is supposed to work in Internet Explorer only. The
                  > "for" and "event" attributes are proprietary Microsoft inventions, and
                  > won't work in any other browser, as is "window.eve nt". To get the
                  > samme effect in both IE and other browsers, I would do:
                  >
                  > <script type="text/javascript">
                  > document.onclic k = function (event) {
                  > event = event || window.event; // IE sucks
                  > /// your code, but with "event" instead of "window.eve nt".
                  > }
                  > </script>
                  > [color=green]
                  > > <!-- Begin[/color]
                  >
                  > HTML-like comments are not necessary in Javascript.
                  > [color=green]
                  > > //window.event.sr cElement.cancel Bubble = true;[/color]
                  >
                  > That would be
                  > window.event.ca ncelBubble = true;
                  > in IE.
                  > [color=green]
                  > > //window.event.re turnValue = true;
                  > > if (frm1.UID.value == ''){[/color]
                  >
                  > Again, a safer, cross browser, method of referring to a form control is:
                  > if (document.forms['frm1'].elements['UID'].value == '') {
                  > Just using the form name as a global value is also IE specific.
                  > [color=green]
                  > > document.frm1.U ID.focus();
                  > > }
                  > > // End -->
                  > > </script>
                  > >
                  > > The UID is the ID for the Input box; frm1 is the name of the Form;
                  > > this script resides within the <HEAD> tag.[/color]
                  >
                  > That means that the user can click the page between the time when the
                  > handler is assigned and the form is loaded. It is not dangerous, but
                  > will give a Javascript error. It would be safer to assign the handler
                  > after the form has been loaded.
                  >
                  >
                  > How I would do it:
                  > ---
                  > <script type="text/javascript">
                  > document.onclic k = function(event) {
                  > // event = event || window.event; // if you need it.
                  > var ctrl = document.forms['frm1'].elements['UID'];
                  > if (ctrl.value == "") {
                  > ctrl.focus();
                  > }
                  > }
                  > </script>
                  > ---
                  > and I would put this code right after the </form> of <form id="frm1" ....>.
                  >
                  >
                  > /L
                  > --
                  > Lasse Reichstein Nielsen - lrn@hotpop.com
                  > DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  > 'Faith without judgement merely degrades the spirit divine.'[/color]

                  Comment

                  Working...