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

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.