Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


function isnumeric : to submit or not submit form?

function isnumeric : to submit or not submit form?

function isnumeric : to submit or not submit form?


I am using a form to search by zip code.  If the visitor does not enter a 5-digit zip code, an alert is generated.  So far, so good.  Search works, alert works.

However if it returns false, when the OK is clicked on the alert, the form submits anyway.  I am seeking a method that will return to the referring page if the zip code entry is not valid, rather than submitting the form.  

in <head> :


<script language="javascript" type="text/javascript">
    function isNumeric(elem, helperMsg){
    var numericExpression = /^\d{5}$/;
        return true;
        return false;

in <body>


<input type="submit" value="GO!" style="font-weight:bold;" onclick="isNumeric(document.getElementById('numbers'), '5-digit Zip Code Please!')">

I have tried <input type="button", which does not submit the form at all.  I have tried putting the onclick routine into the <form> tag as an "onSubmit", same results, submits the form when false.

I have tried reversing the true and false elements in the first <script>


        return false;
        return true;
Submits form, generates alert, but submits form when click OK on alert.  Still no joy.

Any suggestions much appreciated....

One example on www.physioyellow.com

Thanks in advance...


RE: function isnumeric : to submit or not submit form?

Basically you need to return the value from the onclick event or from the onsubmit event.

In other words add a return to your function call:


<input type="submit" value="GO!" style="font-weight:bold;" onclick="return isNumeric(document.getElementById('numbers'), '5-digit Zip Code Please!')">

If your function returns a false value the onClick will return that value as well and cancel the action.  

Phil AKA Vacunita
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.

RE: function isnumeric : to submit or not submit form?

Works like a champ.  Muchisimas Gracias


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close