Form Validation using Javascript inside PHP

Posted by Mikey1980 on Stack Overflow See other posts from Stack Overflow or by Mikey1980
Published on 2010-03-26T12:59:24Z Indexed on 2010/03/26 13:13 UTC
Read the original article Hit count: 343

Filed under:
|

I have a simple problem but no matter what I try I can't see to get it to work. I have a form on a php page and I need to validate the qty value on my form so that it doesn't exceed $qty (value pulled from mySQL) and is not less than zero. Sounds easy--hmm wish it were..lol! I had it checking if the value was numeric and in my attempts to make this work I even broke that--not a good morning..lol!

Here's a snip of my Java Fn:

<script type='text/javascript'>
    function checkQty(elem){
        var numericExpression = /^[0-9]+$/;
        if(elem.value.match(numericExpression)){
                return true;
            }else{
                alert("Quantity for RMA must be greater than zero and less than original order!");
                elem.focus();
                return false;
        }
    }
    </script>

The function is called from the submit button, onClick:

<input type="submit" name="submit" onclick="checkQty(document.getElementById('qty')";">  

I've tried:

var numericExpression = /^[0-9]+$/;
if(elem.value.match(numericExpression) || elem.value < 0 || elem.value > <? int($qty) ?>){

No dice....HELP!?!

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript