Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Label Free JavaScript Form</title>
- <script type="text/javascript">
- // Wait until page is done loading
- window.onload = function()
- {
- var inputTagObjects = document.getElementsByTagName("input");
- var inputTagDefaultValues = new Array();
- for(var i = 0; i < inputTagObjects.length; i++)
- {
- // Only add input elements with a type and name attribute
- if(inputTagObjects[i].hasAttribute("type") && inputTagObjects[i].getAttribute("type") == "text" && inputTagObjects[i].hasAttribute("name"));
- {
- // Make sure the input element has a default value
- if(inputTagObjects[i].hasAttribute("value") == false)
- {
- // Give an empty value attribute
- inputTagObjects[i].setAttribute("value","");
- }
- // Assign default value to global array with the index of the input elements name
- inputTagDefaultValues[inputTagObjects[i].name] = inputTagObjects[i].value;
- // Assign Events
- inputTagObjects[i].onfocus = function()
- {
- console.log(inputTagObjects[i].getAttribute("name") + " has been focused.");
- }
- inputTagObjects[i].onblur = function()
- {
- console.log(inputTagObjects[i].getAttribute("name") + " has been blurred.");
- }
- }
- }
- }
- </script>
- </head>
- <body>
- <div id="form">
- <form method="post" enctype="multipart/form-data">
- <p><input type="text" name="firstName" value="First Name" /></p>
- <p><input type="text" name="lastName" value="Last Name" /></p>
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement