Advertisement
Guest User

"Uncaught TypeError: Cannot call method 'getAttribute' of un

a guest
Jul 22nd, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.59 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Label Free JavaScript Form</title>
  5.         <script type="text/javascript">
  6.             // Wait until page is done loading
  7.             window.onload = function()
  8.             {
  9.                 var inputTagObjects = document.getElementsByTagName("input");
  10.                 var inputTagDefaultValues = new Array();
  11.                 for(var i = 0; i < inputTagObjects.length; i++)
  12.                 {
  13.                     // Only add input elements with a type and name attribute
  14.                     if(inputTagObjects[i].hasAttribute("type") && inputTagObjects[i].getAttribute("type") == "text" && inputTagObjects[i].hasAttribute("name"));
  15.                     {
  16.                         // Make sure the input element has a default value
  17.                         if(inputTagObjects[i].hasAttribute("value") == false)
  18.                         {
  19.                             // Give an empty value attribute
  20.                             inputTagObjects[i].setAttribute("value","");
  21.                         }
  22.                         // Assign default value to global array with the index of the input elements name
  23.                         inputTagDefaultValues[inputTagObjects[i].name] = inputTagObjects[i].value;
  24.                        
  25.                         // Assign Events
  26.                         inputTagObjects[i].onfocus = function()
  27.                         {
  28.                             console.log(inputTagObjects[i].getAttribute("name") + " has been focused.");
  29.                         }
  30.                         inputTagObjects[i].onblur = function()
  31.                         {
  32.                             console.log(inputTagObjects[i].getAttribute("name") + " has been blurred.");
  33.                         }
  34.                     }
  35.                 }
  36.                
  37.             }
  38.         </script>
  39.     </head>
  40.     <body>
  41.         <div id="form">
  42.             <form method="post" enctype="multipart/form-data">
  43.                 <p><input type="text" name="firstName" value="First Name" /></p>
  44.                 <p><input type="text" name="lastName" value="Last Name" /></p>
  45.             </form>
  46.         </div>
  47.     </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement