SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Want to highlight button in HTML page

    Hi everyone,

    Can you please tell me if there is any syntax in HTML which works as "Enter".Actually I want to highlight a button in such a way,if a user press the enter button in keyboard,corressponding HTML page button will be pressed. generally in a web page after filling a form we press the enter button to post the form. Is it possible by HTML coding?? means i don't want to click the button in the web page,just press the enter button in keyboard.


    Please give your valuable response...Thanking you...

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,109
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Hi,

    In most browsers(maybe all ?) all links in a page will behave that way if they are active (e.g. tabbed through).

    With javascript you can handle events like keypress which could do it for you.
    Code javascript:
    <script type="text/javascript" charset="utf-8">
      window.onkeypress = function(event) {
      if (event.keyCode == 13) { // enter key pressed
        //do something
        window.location = 'someplace.html';
      }
    }
    </script>

  3. #3
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,109
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Perhaps a better way is to focus on a link in the page and use the default action of the enter key.
    Code html4strict:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
    	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    	<title>untitled</title>
    <script type="text/javascript" charset="utf-8">
    window.onkeydown = function(event) {
      if (event.keyCode == 13) { // enter key pressed
        document.getElementById('linky').focus();
      }
    }
    </script>
    </head>
    <body>
    	<p>Content</p>
    	<p><a id="linky" href="linky.html">linky linky</a></p>
    </body>
    </html>

  4. #4
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot markbrown4 for your help...It is working now...

  5. #5
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I hope you are not making a page that has a pretty picture or similar and just says hit enter to enter the site...

    All that does is make the user visit two pages to use the site - the hit enter page and the real site. Why not just take them directly into the site by dumping any such page and making the page they go to on hitting enter your index page??? A barrier to entering the site is a barrier that makes people go away.

  6. #6
    SitePoint Member
    Join Date
    Jan 2010
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No John, I am talking about a page where user can fill up a form and submit the form by just pressing the enter button. It is not the 1st page or introductory page. It contains a genuine form. I appreciate your concern but it is not like that...

    Thanking you...

  7. #7
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by seoprostar View Post
    No John, I am talking about a page where user can fill up a form and submit the form by just pressing the enter button. It is not the 1st page or introductory page. It contains a genuine form. I appreciate your concern but it is not like that...
    If you have a form containing <input type="submit">, when a user is typing in a form field and presses 'Enter', that will submit the form in pretty much all mainstream browsers. (Obviously this doesn't work if they are in a textarea, where Enter just starts a new line, but it does the job on an ordinary input field).

    This is one of the advantages of using a proper <input type="submit"> rather than a Javascript submission.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •