这可能是一个我只是没有看到的简单修复,但我正在尝试设置基本的交付区域功能。如果您在交付区域,在提交邮政编码后,警报显示您在我们的区域中,当您单击确定时,它会将您带到预订页面。否则,说他们在该区域之外。我似乎无法获得警报要求进入预订页面的onclick需求。 (P.S.所有javacript进入Squarespace)
<script type="text/javascript">
function IsValidZipCode() {
var zip = document.getElementById('txtZip').value;
var ZipArray = ["60543", "60188"];
var isValid = ZipArray.indexOf(zip); ;
(isValid );
if (isValid >= 0){
alert ('Nice! go ahead and book!')
// NEED TO LINK TO NEW WEBPAGE
return true;
}
else {
alert('Sorry, we do not offer delivery here at this time');
return false;
}
}
</script>
<form>
Please Enter Zip Code: <input id="txtZip" name="zip" type="number" />
<input onclick="IsValidZipCode()" id="Button" type="submit" value="Submit"/>
</form>
答案 0 :(得分:0)
从评论中,您的问题似乎是提交按钮在点击时刷新页面。您需要使用e.preventDefault来防止这种情况。
<input onclick="IsValidZipCode(event)" id="Button" type="submit" value="Submit"/>
function IsValidZipCode(event) {
if (isValid >= 0){
event.preventDefault;
alert ('Nice! go ahead and book!')
window.location.href = 'yoururl.com'
}
}