Created
May 31, 2010 16:30
-
-
Save aarongough/419993 to your computer and use it in GitHub Desktop.
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
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> | |
| <html> | |
| <head> | |
| <title>Simple Form Manipulation</title> | |
| <script type="text/javascript"> | |
| function setupForm () { | |
| var policySearchButton = document.getElementById("policy_search_button"); | |
| var form = policySearchButton.parentNode; | |
| policySearchButton.onclick = function() { | |
| var newInput = document.createElement("input"); | |
| newInput.type = "hidden"; | |
| newInput.name = "namespace"; | |
| newInput.value = "ns1"; | |
| form.appendChild(newInput); | |
| }; | |
| } | |
| </script> | |
| </head> | |
| <body> | |
| <form action="#" method="get"> | |
| <input type="text" name="searchterm" /> | |
| <input id="global_search_button" type="submit" value="Global Search" /> | |
| <input id="policy_search_button" type="submit" value="Policy Search" /> | |
| </form> | |
| <p>Submit the form with both buttons, because it's a GET request you'll see the difference in the resulting URL. In the end it turns out that jQuery was not needed.</p> | |
| <script type="text/javascript"> | |
| setupForm(); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment