calling input button click manually

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

    #1

    calling input button click manually

    In my javascript, when enter key is pressed, I want to simulate the effect
    of clicking a button.

    var mykey;
    var posted=false;

    if (window.Event){
    document.captur eEvents(Event.K EYDOWN);
    }

    document.onkeyd own = myKeyDown;

    function myKeyDown(e){

    if (window.Event){
    mykey = e.which;
    }
    else{
    mykey = event.keyCode;
    }
    //alert(mykey);

    var theform;
    if (window.navigat or.appName.toLo werCase().index Of("netscape") > -1) {
    theform = document.forms["Form1"];
    }
    else {
    theform = document.Form1;
    }

    if ((mykey==13) && (posted==false) && (theform.btnSen d.click))
    {
    posted=true;
    theform.btnSend .click();
    }
    }

    Everything works fine in IE4 to IE6. But NS behaviour is really bizzare.

    Thing work as expected in NS7.

    In NS6, theform.btnSend .click() does not cause form submission.

    In NS4, it complains that theform.btnSend .click() does not exist (despite
    having passed the if test that verifies theform.btnSend .click exists).

    Any idea?

    Thanks


  • Lee

    #2
    Re: calling input button click manually

    CW said:[color=blue]
    >
    >In my javascript, when enter key is pressed, I want to simulate the effect
    >of clicking a button.
    >
    >var mykey;
    > var posted=false;
    >
    > if (window.Event){
    > document.captur eEvents(Event.K EYDOWN);
    > }
    >
    > document.onkeyd own = myKeyDown;
    >
    > function myKeyDown(e){
    >
    > if (window.Event){
    > mykey = e.which;
    > }
    > else{
    > mykey = event.keyCode;
    > }
    > //alert(mykey);
    >
    > var theform;
    > if (window.navigat or.appName.toLo werCase().index Of("netscape") > -1) {
    > theform = document.forms["Form1"];
    > }
    > else {
    > theform = document.Form1;
    > }
    >
    > if ((mykey==13) && (posted==false) && (theform.btnSen d.click))
    > {
    > posted=true;
    > theform.btnSend .click();
    > }
    >}
    >
    >Everything works fine in IE4 to IE6. But NS behaviour is really bizzare.
    >
    >Thing work as expected in NS7.
    >
    >In NS6, theform.btnSend .click() does not cause form submission.
    >
    >In NS4, it complains that theform.btnSend .click() does not exist (despite
    >having passed the if test that verifies theform.btnSend .click exists).
    >
    >Any idea?[/color]

    It's generally a bad idea to do anything as drastic as submit a
    form on keydown. That leaves the keyup event in limbo, with
    unpredictable consequences.

    I don't have NS6 installed, but NS4 submits for me when the button's
    click() method is called.

    Is there a reason why you're calling the click() method, instead of
    just directly invoking the form's submit() method?

    Comment

    • CW

      #3
      Re: calling input button click manually

      because there are 2 buttons on the form. If I call submit, it doesn't
      specify which button is pressed.

      thanx
      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:ckkfe1029n 7@drn.newsguy.c om...[color=blue]
      > CW said:[color=green]
      >>
      >>In my javascript, when enter key is pressed, I want to simulate the effect
      >>of clicking a button.
      >>
      >>var mykey;
      >> var posted=false;
      >>
      >> if (window.Event){
      >> document.captur eEvents(Event.K EYDOWN);
      >> }
      >>
      >> document.onkeyd own = myKeyDown;
      >>
      >> function myKeyDown(e){
      >>
      >> if (window.Event){
      >> mykey = e.which;
      >> }
      >> else{
      >> mykey = event.keyCode;
      >> }
      >> //alert(mykey);
      >>
      >> var theform;
      >> if (window.navigat or.appName.toLo werCase().index Of("netscape") > -1) {
      >> theform = document.forms["Form1"];
      >> }
      >> else {
      >> theform = document.Form1;
      >> }
      >>
      >> if ((mykey==13) && (posted==false) && (theform.btnSen d.click))
      >> {
      >> posted=true;
      >> theform.btnSend .click();
      >> }
      >>}
      >>
      >>Everything works fine in IE4 to IE6. But NS behaviour is really bizzare.
      >>
      >>Thing work as expected in NS7.
      >>
      >>In NS6, theform.btnSend .click() does not cause form submission.
      >>
      >>In NS4, it complains that theform.btnSend .click() does not exist (despite
      >>having passed the if test that verifies theform.btnSend .click exists).
      >>
      >>Any idea?[/color]
      >
      > It's generally a bad idea to do anything as drastic as submit a
      > form on keydown. That leaves the keyup event in limbo, with
      > unpredictable consequences.
      >
      > I don't have NS6 installed, but NS4 submits for me when the button's
      > click() method is called.
      >
      > Is there a reason why you're calling the click() method, instead of
      > just directly invoking the form's submit() method?
      >[/color]


      Comment

      • Lee

        #4
        Re: calling input button click manually

        CW said:[color=blue]
        >
        >because there are 2 buttons on the form. If I call submit, it doesn't
        >specify which button is pressed.[/color]

        You can set a hidden form field to tell which was pressed,
        or better, redesign it so that it will work without Javascript,
        for those who have it disabled.

        Please don't top post. Respond *after* the message you're
        responding to.

        Comment

        Working...