Jquery focus on the correct ID

leNEntertlent

New Member
I have a piece of jQuery code that automatically focuses on an ID of a input box. This was fine when there was only one input field. I have now added another input field. How do I get it to focus on the input field of the last used input box.A user can use to two input boxes to make a search. I want the focus to be on the input box that was last selected by the user.Jquery code below:\[code\]<script>$(document).ready(function() { $("#state").change(function () { this.form.submit();})$('#supplier_name, #aircraft_type').focus()$("#supplier_name, #aircraft_type").val($("#supplier_name, #aircraft_type").val());var typingTimer; var doneTypingInterval = 800; $('#supplier_name, #aircraft_type').keyup(function(){ clearTimeout(typingTimer); if ($('#supplier_name, #aircraft_type').val) { typingTimer = setTimeout(doneTyping, doneTypingInterval); }});function doneTyping () { $("form").submit();}});</script>\[/code\]HTML + ASP CODE BELOW:\[code\] <form id="searchf" action="search.htm" method="get"> <p>Supplier name: <input id="supplier_name" name="supplier_name" type="text" value="http://stackoverflow.com/questions/14576079/<%=src_supplier_name%>"> Aircraft type: <input id="aircraft_type" name="aircraft_type" type="text" value="http://stackoverflow.com/questions/14576079/<%=src_aircraft_type%>"> </p> <p>State or Territory:<br/> <select style="width: 497px;" id="state" name="state"> <option class="group" label="Any state or territory" value="http://stackoverflow.com/questions/14576079/any" <%if request.querystring("state") = "any" then response.write("selected") %>></option> <option class="group" label="Australian Capital Territory" value="http://stackoverflow.com/questions/14576079/ACT" <%if request.querystring("state") = "ACT" then response.write("selected") %>></option> <option class="group" label="New South Whales" value="http://stackoverflow.com/questions/14576079/NSW" <%if request.querystring("state") = "NSW" then response.write("selected") %>></option> <option class="group" label="Northern Territory" value="http://stackoverflow.com/questions/14576079/NT" <%if request.querystring("state") = "NT" then response.write("selected") %>></option> <option class="group" label="Queensland" value="http://stackoverflow.com/questions/14576079/QLD" <%if request.querystring("state") = "QLD" then response.write("selected") %>></option> <option class="group" label="South Australia" value="http://stackoverflow.com/questions/14576079/SA" <%if request.querystring("state") = "SA" then response.write("selected") %>></option> <option class="group" label="Tasmania" value="http://stackoverflow.com/questions/14576079/TAS" <%if request.querystring("state") = "TAS" then response.write("selected") %>></option> <option class="group" label="Victoria" value="http://stackoverflow.com/questions/14576079/VIC" <%if request.querystring("state") = "VIC" then response.write("selected") %>></option> <option class="group" label="Western Australia" value="http://stackoverflow.com/questions/14576079/WA" <%if request.querystring("state") = "WA" then response.write("selected") %>></option> <option class="group" label="Other" value="http://stackoverflow.com/questions/14576079/other" <%if request.querystring("state") = "other" then response.write("selected") %>></option> </select> <input type="submit" value="http://stackoverflow.com/questions/14576079/Search" /></p> </form>\[/code\]
 
Back
Top