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

?>

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.