douzhizao0270 2014-12-12 21:47
浏览 31

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

?>

  • 写回答

1条回答 默认 最新

  • duancuo1234 2014-12-12 21:51
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多