On jQuery keyup on two IDs a function is executed.
$('#supplier_name').keyup(function(){
clearTimeout(typingTimer);
if ($('#supplier_name').val) {
typingTimer = setTimeout(doneTyping, doneTypingInterval);
}
$.cookie("inputFocus", "#supplier_name");
});
After this the form is submitted. I want to do jQuery .focus on the ID which led the keyup function to execute.
So if I entered text into #supplier_name after form submit I want the focus to be on that. Vice versa with #aircraft_type.
EDIT: I am trying to do this via cookies however it doesn’t seem to be working.
How do I do this with the following jQuery code:
<script>
$(document).ready(function() {
$("#state").change(function () {
this.form.submit();
})
$.cookie("inputFocus").focus();
$("#supplier_name").val($("#supplier_name").val());
$("#aircraft_type").val($("#aircraft_type").val());
var typingTimer;
var doneTypingInterval = 800;
$('#supplier_name').keyup(function(){
clearTimeout(typingTimer);
if ($('#supplier_name').val) {
typingTimer = setTimeout(doneTyping, doneTypingInterval);
}
$.cookie("inputFocus", "#supplier_name");
});
$('#aircraft_type').keyup(function(){
clearTimeout(typingTimer);
if ($('#aircraft_type').val) {
typingTimer = setTimeout(doneTyping, doneTypingInterval);
}
$.cookie("inputFocus", "#aircraft_type"); });
function doneTyping () {
$("form").submit();
}
});
</script>
The solution to the above problem was to create an object to use focus() and to add the jQquery cookie plug-in.
The change is below:
“$.cookie(“inputFocus”).focus();” to “$($.cookie(“inputFocus”)).focus()”
Added the below code to the page:
“”