using the key handling function

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

    using the key handling function

    Hello

    I have a piece of simple code which take the user inputs and depending
    which check box is selected directs them to a different page.

    <form name="allform">
    <input type="radio" name="allsearch " value="Weaksear ch">
    <font face="Arial,Hel vetica" >Weak&nbsp;</font><br>
    <input type="radio" name="allsearch " value="Pinserse arch">

    <font face="Arial,Hel vetica" >Pinser&nbsp; </font><br>
    <input type="radio" name="allsearch " value="Brutesea rch">
    <font face="Arial,Hel vetica">Brute note&nbsp;</font> <br>
    <input type="radio" name="allsearch " checked
    value="gogsearc h">
    <font face="Arial,Hel vetica">Google</font> <br>
    <input type=text name=allsearcht ext size=10 maxlength=255>

    <input type="button" onClick="locate all(this)" value="Go"
    name="button">
    </form>

    This works but the user needs to hit the go button, if they just hit
    return the text field is emptied, I would like if the user hits ENTER,
    the search begins.

    I believe I can add something similar as

    if (window.event.k eyCode == 13)

    But I am not sure how to incorporate it in the form?
    --



  • Lasse Reichstein Nielsen

    #2
    Re: using the key handling function

    Paul Kirk <paul.kirk@xili nx.com> writes:
    [color=blue]
    > <input type="button" onClick="locate all(this)" value="Go"
    > name="button">[/color]
    ....[color=blue]
    > This works but the user needs to hit the go button, if they just hit
    > return the text field is emptied,[/color]

    What happens is that the form is submitted. The missing (and
    required!) action attribute is interpreted as pointing to the page
    itself, so the page is reloaded.
    [color=blue]
    > I would like if the user hits ENTER, the search begins.[/color]
    [color=blue]
    > I believe I can add something similar as
    >
    > if (window.event.k eyCode == 13)[/color]

    Overkill.
    Just put the call to locateall in the onsubmit handler of the form tag:

    <form id="allform" onclick="locate all(this)" action="noJS.ht ml">
    (fix the locateall function so it expects the form as argument and not
    the button).

    Change the <input type="button" ...> to
    <input type="submit: value-"Go" name="button">

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • kaeli

      #3
      Re: using the key handling function

      In article <3F8ACA27.D3593 A65@xilinx.com> , paul.kirk@xilin x.com
      enlightened us with...
      [color=blue]
      > This works but the user needs to hit the go button, if they just hit
      > return the text field is emptied, I would like if the user hits ENTER,
      > the search begins.
      >
      > I believe I can add something similar as
      >
      > if (window.event.k eyCode == 13)
      >
      > But I am not sure how to incorporate it in the form?[/color]


      You don't need to - the enter key is submitting the form.
      Try this.

      <form name="allform" onSubmit="locat eall(this);retu rn false;">

      Your Go button calls that function onClick - so you may need to play
      with the "this" keyword, which refers to the button when the button is
      clicked but to the form when the enter key is pressed and the form is
      submitted.

      --
      -------------------------------------------------
      ~kaeli~
      Jesus saves, Allah protects, and Cthulhu
      thinks you'd make a nice sandwich.


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

      Comment

      • Paul Kirk

        #4
        Re: using the key handling function

        Thank you that worked a treat.

        kaeli wrote:
        [color=blue]
        > In article <3F8ACA27.D3593 A65@xilinx.com> , paul.kirk@xilin x.com
        > enlightened us with...
        >[color=green]
        > > This works but the user needs to hit the go button, if they just hit
        > > return the text field is emptied, I would like if the user hits ENTER,
        > > the search begins.
        > >
        > > I believe I can add something similar as
        > >
        > > if (window.event.k eyCode == 13)
        > >
        > > But I am not sure how to incorporate it in the form?[/color]
        >
        > You don't need to - the enter key is submitting the form.
        > Try this.
        >
        > <form name="allform" onSubmit="locat eall(this);retu rn false;">
        >
        > Your Go button calls that function onClick - so you may need to play
        > with the "this" keyword, which refers to the button when the button is
        > clicked but to the form when the enter key is pressed and the form is
        > submitted.
        >
        > --
        > -------------------------------------------------
        > ~kaeli~
        > Jesus saves, Allah protects, and Cthulhu
        > thinks you'd make a nice sandwich.
        > http://www.ipwebdesign.net/wildAtHeart
        > http://www.ipwebdesign.net/kaelisSpace
        > -------------------------------------------------[/color]

        --
        Regards
        Paul Kirk


        / /\/ Paul Kirk Xilinx Inc.
        \ \ Customer Apps Engineer 203 Brooklands Road
        / / Paul.Kirk@xilin x.com Weybridge Surrey KT13 0RH
        \_\/\ Eurosupport@xil inx.com http://support.xilinx.com


        Comment

        Working...