user6716861 user6716861 - 2 months ago 5x
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

$(".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) {