How to edit code for state-based user access restriction?

studio429
Tourist
4 0 1

I'm trying to edit the code I found on https://community.shopify.com/c/shopify-design/site-access-add-age-verification-to-your-online-store...5 so that I can also check their state. I've got the state box entered, and it will pop up an alert, but I can't figure out how to make it so that only certain states are allowed in. We can only ship to certain states, so we want to make that known up front.

 

This is what I have so far for the function:

 

function stateCheck() {
  var legal_state = {{ enter_state }};  // sets legal states
  var state = parseInt(document.getElementById('bystate').value);
  if ((bystate != legal_state)) {
      {alert("this state is not legal. we can not sell to you.")}
  
  } else {
  var state = parseInt(document.getElementById('bystate').value);
  if ((bystate = legal_state)) {
    location.reload();
  }
  }

  }

 

Above that I reference the values of the states that are legal. I only entered for for testing. 

 

{% assign legal_state = 50 %}


<option value="50">WI</option>

 The option value is listed in a drop down in a select area. 

 

Any suggestions? 

Replies 0 (0)