Created
          March 17, 2013 11:45 
        
      - 
      
 - 
        
Save mvolkmann/5181215 to your computer and use it in GitHub Desktop.  
    IE9 form test
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <html> | |
| <head> | |
| <title>Test Form</title> | |
| <script src="form.js"></script> | |
| </head> | |
| <body> | |
| <form id="myform" method="post" action="http://localhost:3000"> | |
| <label for="name">Name:</label> | |
| <input id="name" name="name" type="text"/> | |
| <button type="submit">Go!</button> | |
| </form> | |
| </body> | |
| </html> | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 'use strict'; | |
| window.onload = function () { | |
| console.log('got onload'); | |
| var form = document.getElementById('myform'); | |
| console.log('form =', form); | |
| form.style.borderColor = 'black'; | |
| form.style.borderStyle = 'solid'; | |
| form.style.borderWidth = '3px'; | |
| console.log('form.addEventListener =', form.addEventListener); | |
| var name = document.getElementById('name'); | |
| var listener = function (event) { | |
| console.log('name = "' + name.value + '"'); | |
| console.log('name.length =', name.length); | |
| if (name.value.length === 0) event.preventDefault(); | |
| //if (name.value.length === 0) return false; // works everywhere but IE (tes | |
| ted IE9) | |
| }; | |
| form.addEventListener('submit', listener); | |
| //form.onsubmit = listener; | |
| }; | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment