user6716861 user6716861 - 1 year ago 97
jQuery Question

Moving cursor to input field after click button action

Am looking for a way that a customer on a site can be directed to a mandatory input field once a button is clicked.

Example is here if four products are added to a shopping cart (from köp online) the customer needs to click on Gå till kassan to proceed which should take them to

but at the bottom of the form is a mandatory field Postnummer

Trying to see how we can move the input cursor to that field if empty

Answer Source
$(".action-checkout").on("click",function(e) {
  var $postnummer = $("[name=shipping-postal-code]"), psval = $postnummer .val();
  if ($.trim(psval)=="") {
    e.preventDefault(); // cancel click
    // alert("Fyll i postnummer"); // optional
    $postnummer .focus(); 

It needs to be in the load event. If you ajax in the link, you need to change to something like

$("#content-primary").on("click",".action-checkout",function(e) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download