Input, Buttons and Enter Keys

Discussion in 'Javascript' started by Omicron, Mar 25, 2008.

  1. Omicron

    Omicron Guest

    Hello,
    Can someone lead me in the right direct with this request:
    Please look at the piece of code below:

    <table summary="Sort Buttons">
    <tr>
    <td>
    <input onclick="justSong_filter()" type="button" value="Song Search" /
    >

    <input type="text" id="newSong" />
    </td>
    </tr></table>

    As you can see, an input box is opened and when the user enters his
    search phrase AND CLICKS THE BUTTON, the javascript contained in
    justSong_filter() does its thing, etc., etc.
    All works fine.

    What I'd like, however, is to have NO BUTTON at all. None. What I want
    to happen is that the user enters his search phrase and then have him
    HIT THE ENTER KEY on the keyboard to initiate the javascript, as
    occurs in the original code above.

    Currently, after the user enters his search phrase, hitting the Enter
    Key does nothing at all. He must click on the Button.

    Can someone show me how to re-code the above activity to perform as it
    currently does, but to have no button and using the Enter Key as the
    final firing sequence?

    I thought it would be pretty straight forward - seems I am wrong!
    I've messed with this for about 3 days and I've gotten nowhere, so I
    must be looking/thinking in the wrong place.

    Any help, as always, would be greatly appreciated.
    Regards.
    Omicron, Mar 25, 2008
    #1
    1. Advertising

  2. Omicron wrote:

    > Can someone lead me in the right direct with this request:
    > Please look at the piece of code below:
    >
    > <table summary="Sort Buttons">
    > <tr>
    > <td>
    > <input onclick="justSong_filter()" type="button" value="Song Search" /
    >
    > <input type="text" id="newSong" />
    > </td>
    > </tr></table>
    >
    > As you can see, an input box is opened and when the user enters his
    > search phrase AND CLICKS THE BUTTON, the javascript contained in
    > justSong_filter() does its thing, etc., etc.
    > All works fine.
    >
    > What I'd like, however, is to have NO BUTTON at all. None. What I want
    > to happen is that the user enters his search phrase and then have him
    > HIT THE ENTER KEY on the keyboard to initiate the javascript, as
    > occurs in the original code above.
    >
    > Currently, after the user enters his search phrase, hitting the Enter
    > Key does nothing at all. He must click on the Button.
    >
    > Can someone show me how to re-code the above activity to perform as it
    > currently does, but to have no button and using the Enter Key as the
    > final firing sequence?
    >
    > I thought it would be pretty straight forward - seems I am wrong!
    > I've messed with this for about 3 days and I've gotten nowhere, so I
    > must be looking/thinking in the wrong place.


    <input type="text" onKeyPress="
    var key;
    if (window.event)
    key = window.event.keyCode;
    else if (event)
    key = event.which;
    if (key == 10 || key == 13)
    alert('You have hit Enter!');
    ">

    Cheers,

    --
    Bart
    Bart Van der Donck, Mar 25, 2008
    #2
    1. Advertising

  3. Omicron wrote:
    > Can someone lead me in the right direct with this request:
    > Please look at the piece of code below:
    >
    > <table summary="Sort Buttons">
    > <tr>
    > <td>
    > <input onclick="justSong_filter()" type="button" value="Song Search" /
    > <input type="text" id="newSong" />
    > </td>
    > </tr></table>


    Avoid XHTML on the Web, IE does not even support it. Your markup is not
    Valid XHTML and it does not make sense anyway (a one-row one-column table?).

    > [...]
    > What I'd like, however, is to have NO BUTTON at all. None. What I want
    > to happen is that the user enters his search phrase and then have him
    > HIT THE ENTER KEY on the keyboard to initiate the javascript, as
    > occurs in the original code above.
    > [...]
    > Can someone show me how to re-code the above activity to perform as it
    > currently does, but to have no button and using the Enter Key as the
    > final firing sequence?


    <form action="server_side_script" onsubmit="return justSong_filter(this)">
    <fieldset>
    <legend>Song Filter</legend>
    <input name="newSong">
    <input type="submit" value="Apply">
    </fieldset>
    </form>

    justSong_filter() must return `false' if filtering was successful, `true'
    otherwise. However, you will need that submit button so that it also works
    without client-side script support; you may use type="image" or style it
    with CSS.

    Please do not SHOUT, see http://rfc-editor.org/rfc/rfc1855.txt


    F'up2 cljs because this is not JScript-specific

    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann
    Thomas 'PointedEars' Lahn, Mar 25, 2008
    #3
  4. Omicron

    SAM Guest

    Omicron a écrit :
    > <td>
    > <input onclick="justSong_filter()" type="button" value="Song Search" /
    > <input type="text" id="newSong" />
    > </td>
    >
    > What I'd like, however, is to have NO BUTTON at all. None. What I want
    > to happen is that the user enters his search phrase and then have him
    > HIT THE ENTER KEY on the keyboard to initiate the javascript, as
    > occurs in the original code above.



    <form action="#" onsubmit="justSong_filter();return false;">
    Choice :<input type="text" id="newSong" />
    </form>

    Works since NC3 (if there is only one text-field)
    modern browsers work same way but with bigger forms


    Can also try :

    <input type="text" id="newSong"
    onkeyup="var e=null; if(typeof event =='object') e=event;
    if(event.keyCode == 13) justSong_filter();
    return false;" />


    --
    sm
    SAM, Mar 25, 2008
    #4
  5. Omicron

    Omicron Guest

    On Mar 25, 6:10 am, Bart Van der Donck <> wrote:
    > Omicron wrote:
    > > Can someone lead me in the right direct with this request:
    > > Please look at the piece of code below:

    >
    > > <table summary="Sort Buttons">
    > > <tr>
    > > <td>
    > > <input onclick="justSong_filter()" type="button" value="Song Search" /

    >
    > > <input type="text" id="newSong" />
    > > </td>
    > > </tr></table>

    >
    > > As you can see, an input box is opened and when the user enters his
    > > search phrase AND CLICKS THE BUTTON, the javascript contained in
    > > justSong_filter() does its thing, etc., etc.
    > > All works fine.

    >
    > > What I'd like, however, is to have NO BUTTON at all. None. What I want
    > > to happen is that the user enters his search phrase and then have him
    > > HIT THEENTERKEYon the keyboard to initiate the javascript, as
    > > occurs in the original code above.

    >
    > > Currently, after the user enters his search phrase, hitting theEnter
    > >Keydoes nothing at all. He must click on the Button.

    >
    > > Can someone show me how to re-code the above activity to perform as it
    > > currently does, but to have no button and using theEnterKeyas the
    > > final firing sequence?

    >
    > > I thought it would be pretty straight forward - seems I am wrong!
    > > I've messed with this for about 3 days and I've gotten nowhere, so I
    > > must be looking/thinking in the wrong place.

    >
    > <input type="text" onKeyPress="
    > varkey;
    > if (window.event)
    > key= window.event.keyCode;
    > else if (event)
    > key= event.which;
    > if (key== 10 ||key== 13)
    > alert('You have hitEnter!');
    > ">
    >
    > Cheers,
    >
    > --
    > Bart


    Thanks to Sam and Bart and (I guess) Thomas, even though I didn't
    really understand a word of what Thomas was trying to tell me, other
    than I was shouting and in the wrong group (I think).
    Anyway, Thanks to all.
    Unfortunately, none of the suggestions, at least in the manner I have
    tried to implement them, have worked for me.
    When I try all the suggestions, essentially one of two things occurs:
    Either nothing happens when I press the Return Key, or I get a crash
    that buries my TopStyle editor.
    If any of you kind folks would like to see if you can get further
    into my apparently thick skull, I'd appreciate any additional
    comments, leads, references or code you'd like to take the time to
    write.
    Regards.
    Omicron, Mar 26, 2008
    #5
  6. Omicron

    SAM Guest

    Omicron a écrit :
    > On Mar 25, 6:10 am, Bart Van der Donck <> wrote:
    >> Omicron wrote:
    >>> Can someone lead me in the right direct with this request:
    >>> Please look at the piece of code below:
    >>> <table summary="Sort Buttons">
    >>> <tr>
    >>> <td>
    >>> <input onclick="justSong_filter()" type="button" value="Song Search" /
    >>> <input type="text" id="newSong" />
    >>> </td>
    >>> </tr></table>
    >>> As you can see, an input box is opened and when the user enters his
    >>> search phrase AND CLICKS THE BUTTON, the javascript contained in
    >>> justSong_filter() does its thing, etc., etc.
    >>> All works fine.
    >>> What I'd like, however, is to have NO BUTTON at all.


    >> <input type="text" onKeyPress="
    >> varkey;
    >> if (window.event)
    >> key= window.event.keyCode;
    >> else if (event)
    >> key= event.which;
    >> if (key== 10 ||key== 13)
    >> alert('You have hitEnter!');
    >> ">
    >>

    >
    > Thanks to Sam and Bart and (I guess) Thomas,
    > Unfortunately, none of the suggestions, at least in the manner I have
    > tried to implement them, have worked for me.
    > When I try all the suggestions, essentially one of two things occurs:
    > Either nothing happens when I press the Return Key, or I get a crash
    > that buries my TopStyle editor.


    What does an editor has to do here activating JavaScript ?
    You must try in a navigator the given codes inserted in a web page.

    > If any of you kind folks would like to see if you can get further
    > into my apparently thick skull, I'd appreciate any additional
    > comments, leads, references or code you'd like to take the time to
    > write.


    Would it be possible to see something working that we could understand
    what just-a-song-in-my-bathroom make and how.


    references ? Google can gives a lot of them.
    mine are in french. Are you interested ?

    --
    sm
    SAM, Mar 27, 2008
    #6
  7. Omicron

    Omicron Guest

    On Mar 26, 8:05 pm, SAM <>
    wrote:
    > Omicron a écrit :
    >
    >
    >
    > > On Mar 25, 6:10 am, Bart Van der Donck <> wrote:
    > >> Omicron wrote:
    > >>> Can someone lead me in the right direct with this request:
    > >>> Please look at the piece of code below:
    > >>> <table summary="Sort Buttons">
    > >>> <tr>
    > >>> <td>
    > >>> <input onclick="justSong_filter()" type="button" value="Song Search" /
    > >>> <input type="text" id="newSong" />
    > >>> </td>
    > >>> </tr></table>
    > >>> As you can see, an input box is opened and when the user enters his
    > >>> search phrase AND CLICKS THE BUTTON, the javascript contained in
    > >>> justSong_filter() does its thing, etc., etc.
    > >>> All works fine.
    > >>> What I'd like, however, is to have NO BUTTON at all.
    > >> <input type="text" onKeyPress="
    > >> varkey;
    > >> if (window.event)
    > >> key= window.event.keyCode;
    > >> else if (event)
    > >> key= event.which;
    > >> if (key== 10 ||key== 13)
    > >> alert('You have hitEnter!');
    > >> ">

    >
    > > Thanks to Sam and Bart and (I guess) Thomas,
    > > Unfortunately, none of the suggestions, at least in the manner I have
    > > tried to implement them, have worked for me.
    > > When I try all the suggestions, essentially one of two things occurs:
    > > Either nothing happens when I press the ReturnKey, or I get a crash
    > > that buries my TopStyle editor.

    >
    > What does an editor has to do here activating JavaScript ?
    > You must try in a navigator the given codes inserted in a web page.
    >
    > > If any of you kind folks would like to see if you can get further
    > > into my apparently thick skull, I'd appreciate any additional
    > > comments, leads, references or code you'd like to take the time to
    > > write.

    >
    > Would it be possible to see something working that we could understand
    > what just-a-song-in-my-bathroom make and how.
    >
    > references ? Google can gives a lot of them.
    > mine are in french. Are you interested ?
    >
    > --
    > sm


    Hi Sam,
    I use TopStyle editor for coding all my HTML/CSS. It will then load
    the code into IE or whatever browser you tell it to for purposes of
    testing. All my other JS works via the editor so I don' think that is
    relevant to my problem.

    You are most welcome to check out the site I'm building for a friend.
    Go to:
    gtmick.com

    Then, from the drop-down menu on the right, pick any of the Music
    Databases. Once there, you will see the Search Feature that is in
    place, which requires you to enter a search string and then click on
    the button. It is here that I'd like to eliminate the button and just
    allow the user to hit the Enter Key when ready.

    Thanks for your interest.
    Regards.
    Omicron, Mar 27, 2008
    #7
  8. Omicron

    SAM Guest

    Omicron a écrit :
    >
    > Hi Sam,
    > I use TopStyle editor for coding all my HTML/CSS. It will then load
    > the code into IE or whatever browser you tell it to for purposes of
    > testing.


    Ha! OK ! so it isn't the editor that displays the rendered pages.

    > You are most welcome to check out the site I'm building for a friend.
    > Go to:
    > gtmick.com


    Sory not more help can be given, I'd get that :
    "Sorry
    But it appears that you are not using a Microsoft Internet Explorer browser"

    No I'mn't !


    What are the reasons to limit the acces to IE (> 5.5) ?
    Except you're using an applet.
    (needs activeX ?)

    The used functions are relative to this applet.
    Search in its specifications, help and so on ?

    Remember you have to fix the specific functions for this applet :

    function justTitle_filter()
    {
    TDC1.FilterColumn="Title";
    TDC1.FilterValue=newTitle.value;
    TDC1.FilterCriterion="=";
    TDC1.CaseSensitive = false;
    TDC1.Reset();
    }

    where : FilterColumn="Title";
    could be what the applet looks for.
    ( probably the field named 'Title' ?)

    --
    sm
    SAM, Mar 27, 2008
    #8
  9. Omicron

    Omicron Guest

    On Mar 27, 9:00 am, SAM <>
    wrote:
    > Omicron a écrit :
    >
    >
    >
    > > Hi Sam,
    > > I use TopStyle editor for coding all my HTML/CSS. It will then load
    > > the code into IE or whatever browser you tell it to for purposes of
    > > testing.

    >
    > Ha! OK ! so it isn't the editor that displays the rendered pages.
    >
    > > You are most welcome to check out the site I'm building for a friend.
    > > Go to:
    > > gtmick.com

    >
    > Sory not more help can be given, I'd get that :
    > "Sorry
    > But it appears that you are not using a Microsoft Internet Explorer browser"
    >
    > No I'mn't !
    >
    > What are the reasons to limit the acces to IE (> 5.5) ?
    > Except you're using an applet.
    > (needs activeX ?)
    >
    > The used functions are relative to this applet.
    > Search in its specifications, help and so on ?
    >
    > Remember you have to fix the specific functions for this applet :
    >
    > function justTitle_filter()
    > {
    > TDC1.FilterColumn="Title";
    > TDC1.FilterValue=newTitle.value;
    > TDC1.FilterCriterion="=";
    > TDC1.CaseSensitive = false;
    > TDC1.Reset();
    > }
    >
    > where : FilterColumn="Title";
    > could be what the applet looks for.
    > ( probably the field named 'Title' ?)
    >
    > --
    > sm


    Hi Sam,
    Once again, thank you for your reply and help.
    The reason for the IE-only situation is that I am using Tabular Data
    Control (TDC), which is a Microsoft ActiveX control that can be hosted
    by Microsoft Internet Explorer 4.0 and later to display data stored in
    a delimited text file. This current web site is a continuation of a
    friend's 10+ year project which began, back then, using TDC.
    As I noted in my first message, the system is currently fully
    functional and works as advertised. It is just that some of the more
    "mature" users of his site get confused with entering search criteria,
    clicking buttons, etc. I was hoping to just re-code that section and
    allow them to enter their search criteria and hit the Enter Key. That
    was the whole point of this thread.
    Thanks again!
    Regards.
    Omicron, Mar 27, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antonio Lopez Arredondo

    multiline message boxes and ENTER keys.....

    Antonio Lopez Arredondo, Nov 12, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    340
  2. Roger
    Replies:
    1
    Views:
    623
    GreggTB
    May 20, 2005
  3. Guy
    Replies:
    5
    Views:
    2,820
    brucie
    Dec 13, 2003
  4. =?Utf-8?B?am9l?=
    Replies:
    0
    Views:
    730
    =?Utf-8?B?am9l?=
    Sep 28, 2006
  5. HopfZ
    Replies:
    0
    Views:
    559
    HopfZ
    Aug 28, 2006
Loading...

Share This Page