动态HTML文本框和PHP的Javascript验证

Okay so I've searched multiple questions that are similar to mine, but aren't quite the same problem. All I'm trying to do is check each textbox in a table to see if it is a numerical value or not. This textbox has a quantity value, so it should only take numbers. Most of my code's in HTML and PHP.

The hidden input is a numerical value that creates the number of rows in the table that comes from the previous page.

I feel like I'm so close but yet so far away....

function validate() { var submitOK = true; var alertstring = ""; var x1 = document.getElementsByClassName('validate-it'); for(var i=0; i

" />

    <? 




            $userinput = $_POST['productnumber'];
            $count = 0;


        do { 

            echo '<tr>'; ?>
            <td>
            <select name="product<?=$count?>" rel="cost<?=$count?>">
            <option value="0"></option> <?          

            $sql1 = "select product_id, product_name from product";
            $rs=mysqli_query($db,$sql1);

             while($row=mysqli_fetch_array($rs)){ ?>
                <option selected="selected" value="<?=$row[0] ?>"><?= $row[1] ?></option> 
                <?}?></select> 
        <?  echo '<td> <input type="text" class="validate-it" name="quantity' .$count. '" value="" /> </td>';
            echo '<td> <input type="text" id="cost'.$count.'" name="unitprice' .$count. '" value="" /> </td>';
            echo '<td id="totalprice".$count>  </td>';
            echo '</tr>';

            $count = $count + 1;
        }
        while($count < $userinput);

?>

I might be wrong, but I believe you should "register" new dynamic HTML elements you add on your page in order for jQuery to be aware of them.

Here are few useful links, in case everything else is working for you - then you just need to bind your new elements to these events and you'll be good to go:

Event binding on dynamically created elements?

Jquery how to bind click event on dynamically created elements?

Hope it helps! :)