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>
$('#supplier_name, #aircraft_type').val
to be$(this).val()
– Musa$.cookie()
returns the cookie value, you have to create a jQuery object to usefocus()
like this:$($.cookie("inputFocus")).focus()
. What errors do you get in the JS console or does nothing happen at all? – Dehalion