Created
April 9, 2012 16:50
-
-
Save mikedfunk/2344684 to your computer and use it in GitHub Desktop.
IE Multiple Submit Button Test - Working
This file contains 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> | |
<html> | |
<head> | |
<title>IE Submit button test</title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
<link rel="stylesheet" type="text/css" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" /> | |
<style type="text/css"> | |
body { | |
padding: 40px; | |
} | |
</style> | |
<!-- HTML5 shim, for IE6-8 support of HTML elements --> | |
<!--[if lt IE 9]> | |
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script> | |
<![endif]--> | |
<script type="text/javascript"> | |
$(function() | |
{ | |
// on clicking one of the submit buttons | |
$('button').click(function() | |
{ | |
// get the data-value and assign it to the hidden action field | |
var submit_val = $(this).attr('data-value'); | |
$('[name="action"]').val(submit_val); | |
}); | |
// form submit, just to allow js to set the value before submitting | |
$('form').submit(function(e) | |
{ | |
e.preventDefault(); | |
$(this).unbind('submit').submit(); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>IE Multiple Submit Button Test</h1> | |
<hr /> | |
<form method="post" action="<?=$_SERVER['SCRIPT_NAME']?>" class="form-horizontal"> | |
<input type="text" name="test_input" value="test" /> | |
<input type="hidden" name="action" value="value one" /> | |
<button data-value="value one" class="btn" type="submit">Submit One</button> | |
<button data-value="value two" class="btn" type="submit">Submit Two</button> | |
</form> | |
<?php if (count($_POST) > 0): ?> | |
<p class="alert alert-success">Action is <strong><?=$_POST['action']?></strong></p> | |
<?php else: ?> | |
<p class="alert">Click a submit button</p> | |
<?php endif; ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment