Before
After
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript"> // Assign the value to the input with the id passed in function changeTheWorld( idRef, val ) { // Make sure browser supports getElementById if(!document.getElementById ) return; // Find the input by it's id var inputObj = document.getElementById( idRef ); if( inputObj ) { // Update the value inputObj.value = val; } } // Attach all of the behaviors requiured on the page function attachBehaviors() { // Make sure browser supports getElementById if(!document.getElementById ) return; // Find the link by it's id var linkObj = document.getElementById( 'yourLink' ); if( linkObj ) { // Attach the onclick handler linkObj.onclick = function() { changeTheWorld( 'yourInput', 'Hello Dolly' ); }; } } // Define the onload method and tell it to attachBehaviors window.onload = function() { attachBehaviors(); }; </script> </head> <body> <form name='yourForm' action=""> <div> <input type='text' name='yourInput' id='yourInput' value='Hello World'> <a href='#yourInput' id='yourLink'>Change the world!</a> </div> </form> </body> </html>


No comments:
Post a Comment