Forum Discussion

LijaHarris's avatar
LijaHarris
Qrew Trainee
2 years ago

Code Page: Javascript Function Prompt or Alert

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 non-valid zip code.  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 (well a couple examples).  Is it the OnChange that is not working (On the Form:)?  I would like the promp to ideally happen oninput instead since its a input field.  For reference inputzip would be what the user inputs.  That could also be incorrect possibly and there's another way to get the user's input:

<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
------------------------------

3 Replies

    • LijaHarris's avatar
      LijaHarris
      Qrew Trainee
      I figured some of this out.  I have gotten the prompt to work in the console, but how do I get it to work in the code page?



      ------------------------------
      Lija Harris
      ------------------------------
      • RyanStanford2's avatar
        RyanStanford2
        Qrew Member
        Hey Lija,

        From the code in your original question, you set the input variable to include the field xml tags of the xml api...

        var inputzip = "<field fid='16'>" + $("input[name=_fid_16]").val() + "</field>";

        So you comparison is trying to compare with those tags. 

        What you are probably looking for is more like:

        var inputzip = $("input[name=_fid_16]").val();

        ------------------------------
        Ryan Stanford
        ------------------------------