1

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

?>

elephantCoder
  • 13
  • 1
  • 6

1 Answers1

0

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! :)

Community
  • 1
  • 1
d-wade
  • 621
  • 7
  • 9
  • I'm not exactly jquery savvy, that's why I've got my code written in javascript.... so how would I go about doing it in javascript? – elephantCoder Dec 12 '14 at 22:01
  • @elephantCoder I'm not sure about pure JS, but it would be wise to use jQuery at least for this one thing, even if you don't use it in the rest of your code. No need to reinvent the wheel :) But I guess it's doable in pure JS code.. good luck either way! :) – d-wade Dec 13 '14 at 23:37