Skip to content

Instantly share code, notes, and snippets.

@aarongough
Created May 31, 2010 16:30
Show Gist options
  • Save aarongough/419993 to your computer and use it in GitHub Desktop.
Save aarongough/419993 to your computer and use it in GitHub Desktop.
<!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