Hi Lija,
Update the field on the form to include the id and remove the onChange attribute:
<tr>
<td style="font-family: Sans-serif;" class="m">Zip Code:*</td>
<td class="m"><input type="text" size="60" id="_fid_16" name="_fid_16"/></td>
</tr>
Instead of the CheckForZip function, you can add an event listener to the field:
<script language="javascript">
var fid16 = document.getElementById('_fid_16');
fid16.addEventListener('change', (event) => {
var zipcode = ["94602", "95616"]
if (zipcode.includes(event.target.value)) {
alert('yes');
}
});
</script>
Hope that helps!
------------------------------
Doug Henning
------------------------------
Original Message:
Sent: 01-10-2023 09:31
From: Lija Harris
Subject: CODE PAGE: Javascript OnInput Function with Resulting Prompt or Alert (No UPS needs to Be QuickBase/Code Page Native!
Hi,
I have a code page where users can input their information and it goes directly into QuickBase in Javascript and HTML. Our clients were wondering if a prompt could be given to users if they entered in a zip code that is not in their service area - like the Zip Code is not found in their LIST. Here is what I have so far but it is not working. As can be seen below, the fid is 16 of the field users input their zip code into. Zip Code is my LIST the client gave me (I gave a couple examples). I believe the OnChange is not working and instead should be OnInput? I would like the promp to ideally happen oninput instead since its a input field. For reference zip field (fid 16) would be what the user inputs. Otherwise is ther another way to get the user's input, check if its included in a LIST, and if not have text or a Pop up or Alert?:
<script lang="javascript">
function CheckForZip
{
var zipcode = [94602,95616]
var inputzip = "<field fid='16'>" + $("input[name=_fid_16]").val() + "</field>";
if (zipcode.includes(inputzip)) {
alert ('yes');
}
}
On the form:
<tr><td style="font-family: Sans-serif;" class=m>Zip Code:*</td>
<td class=m><input type=text size=60 onChange=CheckForZip name=_fid_16 ></td></tr>
------------------------------
Lija Harris
------------------------------