SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    simple silly login form using JS

    this is for educational purposes... using this in real life is silly for obvious reasons...

    I have a login form: name, password and submit button
    on submit I want to call a JS function to check if the name and password are certain combination and if so forward the page to another html doc, otherwise display some error

    how do I go about this...?

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script type="text/javascript">
    window.onload = function() {
    var contactFormRef = document.getElementById('contactForm');
    contactFormRef.onsubmit = function() {
    var nameRef = document.getElementById('theName');
    if (nameRef.value == '') {
    alert('its blank!');
    }
    }
    }
    </script>
    
    
    <form id="contactForm">
    <input id="theName" type="text">
    <input id="thePassword" type="text">
    </form>
    This should help start you out.

  3. #3
    SitePoint Zealot
    Join Date
    Jan 2006
    Posts
    190
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, one question...
    when I input correct info, the browser doesn't go to http address, similarly when I leave it blank the error layer shows up but the page gets reloaded right away. I don't know maybe that's what it's doing (reloading itself) in the correct input instance as well...

    How do I make this work?
    Code:
    <script type="text/javascript">
    
    window.onload = function() {
    var contactFormRef = document.getElementById('contactForm');
    contactFormRef.onsubmit = function() {
    var nameRef = document.getElementById('theName');
    var passRef = document.getElementById('thePassword');
    
    if (nameRef.value == 'test' && passRef.value == 'test') {
    window.location('http://www.google.com'); 
    } else {
    showHideLayers('errorInfo','','show');
    }
    }
    }
    }
    
    </script>

  4. #4
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    set the action value to the URL, remove the window.location

    <form action="lol.com">

    after the line with showHideLayers() add return false;


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
  •