Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:42:44+00:00 2026-05-10T18:42:44+00:00

I’m working on a simple javascript login for a site, and have come up

  • 0

I’m working on a simple javascript login for a site, and have come up with this:

<form id='loginwindow'> <strong>Login to view!</strong> <p><strong>User ID:</strong>   <input type='text' name='text2'> </p> <p><strong>Password:</strong> <input type='password' name='text1'><br>   <input type='button' value='Check In' name='Submit' onclick=javascript:validate(text2.value,'username',text1.value,'password') /> </p>  </form> <script language = 'javascript'>  function validate(text1,text2,text3,text4) {  if (text1==text2 && text3==text4)  load('album.html');  else   {   load('failure.html');  } } function load(url) {  location.href=url; } </script> 

…which works except for one thing: hitting enter to submit the form doesn’t do anything. I have a feeling it’s cause I’ve used ‘onclick’ but I’m not sure what to use instead. Thoughts?


Okay yeah so I’m well aware of how flimsy this is security-wise. It’s not for anything particularly top secret, so it’s not a huge issue, but if you guys could elaborate on your thoughts with code, I’d love to see your ideas. the code i listed is literally all I’m working with at this point, so I can start from scratch if need be.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:42:45+00:00Added an answer on May 10, 2026 at 6:42 pm

    There are several topics being discussed at once here. Let’s try to clarify.

    1. Your Immediate Concern:

    (Why won’t the input button work when ENTER is pressed?)

    Use the submit button type.

    <input type='submit'.../>  

    ..instead of

    <input type='button'.../> 

    Your problem doesn’t really have anything to do with having used an onclick attribute. Instead, you’re not getting the behavior you want because you’ve used the button input type, which simply doesn’t behave the same way that submit buttons do.

    In HTML and XHTML, there are default behaviors for certain elements. Input buttons on forms are often of type ‘submit’. In most browsers, ‘submit’ buttons fire by default when ENTER is pressed from a focused element in the same form element. The ‘button’ input type does not. If you’d like to take advantage of that default behavior, you can change your input type to ‘submit’.

    For example:

    <form action='/post.php' method='post'>     <!--      ...     -->     <input type='submit' value='go'/> </form> 

    2. Security concerns:

    @Ady mentioned a security concern. There are a whole bucket of security concerns associated with doing a login in javascript. These are probably outside of the domain of this question, especially since you’ve indicated that you aren’t particularly worried about it, and the fact that your login method was actually just setting the location.href to a new html page (indicating that you probably don’t have any real security mechanism in place).

    Instead of drudging that up, here are links to related topics on SO, if anyone is interested in those questions directly.

    • Is there some way I can do a user validation client-side?
    • Encrypting Ajax calls for authentication in jQuery

    3. Other Issues:

    Here’s a quick cleanup of your code, which just follows some best practices. It doesn’t address the security concern that folks have mentioned. Instead, I’m including it simply to illustrate some healthy habits. If you have specific questions about why I’ve written something a certain way, feel free to ask. Also, browse the stack for related topics (as your question may have already been discussed here).

    The main thing to notice is the removal of the event attributes (onclick=”, onsubmit=”, or onkeypress=”) from the HTML. Those belong in javascript, and it’s considered a best practice to keep the javascript events out of the markup.

    <form action='#' method='post' id='loginwindow'>     <h3>Login to view!</h3>     <label>User ID: <input type='text' id='userid'></label>     <label>Password: <input type='password' id='pass'></label>     <input type='submit' value='Check In' /> </form>  <script type='text/javascript'> window.onload = function () {     var loginForm = document.getElementById('loginwindow');     if ( loginwindow ) {         loginwindow.onsubmit = function () {              var userid = document.getElementById('userid');             var pass = document.getElementById('pass');              // Make sure javascript found the nodes:             if (!userid || !pass ) {                 return false;             }              // Actually check values, however you'd like this to be done:             if (pass.value !== 'secret')  {                 location.href = 'failure.html';             }              location.href = 'album.html';             return false;         };     } }; </script> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 64k
  • Answers 64k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer According to the WD spec The setRequestHeader() method appends a… May 11, 2026 at 10:42 am
  • added an answer From this you conclude that the indexer on a list… May 11, 2026 at 10:42 am
  • added an answer Preferences → Privacy → remove individual cookies They are grouped… May 11, 2026 at 10:42 am

Related Questions

I keep getting tasks that are above my skill level. How can I address this without coming accross as grossly incompetent?
I have a web-service that I will be deploying to dev, staging and production.
I'm thinking of starting a wiki, probably on a low cost LAMP hosting account.
I have the following tables in my database that have a many-to-many relationship, which
I'm using the RESTful authentication Rails plugin for an app I'm developing. I'm having
I recently printed out Jeff Atwood's Understanding The Hardware blog post and plan on
I find that getting Unicode support in my cross-platform apps a real pain in
I would like to test a string containing a path to a file for
I'm getting this problem: PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable
I'm an Information Architect and JavaScript developer by trade nowadays, but recently I've been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.