Browse files

Highlight first field on page load, enter sends submit request, doubl…

…e quote to single quote. Submission focuses first field again
  • Loading branch information...
1 parent 8339cb3 commit af76dd0fd44301a6434d193626f8bf309eee8b26 @tony tony committed Oct 19, 2012
Showing with 17 additions and 5 deletions.
  1. +17 −5 examples/jqueryexample/templates/index.html
View
22 examples/jqueryexample/templates/index.html
@@ -2,20 +2,32 @@
{% block body %}
<script type=text/javascript>
$(function() {
- $('a#calculate').bind('click', function() {
+ var submit_form = function(e) {
$.getJSON($SCRIPT_ROOT + '/_add_numbers', {
a: $('input[name="a"]').val(),
b: $('input[name="b"]').val()
}, function(data) {
- $("#result").text(data.result);
+ $('#result').text(data.result);
+ $('input[name=a]').focus().select();
});
return false;
+ };
+
+ $('a#calculate').bind('click', submit_form);
+
+ $('input[type=text]').bind('keydown', function(e) {
+ if (e.keyCode == 13) {
+ submit_form(e);
+ }
});
+
+ $('input[name=a]').focus();
});
</script>
<h1>jQuery Example</h1>
-<p><input type=text size=5 name=a> +
- <input type=text size=5 name=b> =
- <span id=result>?</span>
+<p>
+ <input type=text size=5 name=a> +
+ <input type=text size=5 name=b> =
+ <span id=result>?</span>
<p><a href=# id=calculate>calculate server side</a>
{% endblock %}

0 comments on commit af76dd0

Please sign in to comment.