douan4106 2015-11-16 00:51
浏览 32
已采纳

从文本框中检索值

I have textbox , i want to retrive the value from the textbox and store it in a php variable . Its not inside a form tag. I am creating a e-commerce website for my class assignment . I retrive each product and display it in the website. I have a quantity text box and a "add to cart button". The value in the cart need to be added to the database

while($row_pro =mysqli_fetch_array($row_mysql) )
{
    $product_id=$row_pro['productID'];
    $product_name =$row_pro['productName'];
    $product_desc= $row_pro['productDesc'];
    $product_price= $row_pro['price'];
    $product_vendor=$row_pro['Vendor'];
    $product_images=$row_pro['image'];
    echo "<a href='detail.php?productID=$product_id'><h3>$product_name</h3></a>
                <a href='detail.php?productID=$product_id'><img src='images/$product_images' width='180px' height='280px'/></a>
                <p>$product_desc</p>
                <p>$product_vendor</p>
                <h4>$product_price</h4>
                <input type='text' name='quantity'>
                <a href='product_display.php?addtocart=$product_id'><button style=\"float:right\">Add to cart</button></a>
        ";
}
  • 写回答

1条回答 默认 最新

  • duanlu7223 2015-11-16 01:08
    关注

    You could do something like this:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <input type='text' name='quantity' />
    <a id="linkclicker" href='product_display.php?addtocart=1'><button>Add to cart</button></a>
    <script type="text/javascript">
    $('#linkclicker').click(function() {
        var quant = $('input[name="quantity"]').val();
        $(this).attr('href', $(this).attr('href') + '&param=' + quant);
    });
    </script>
    

    Change param to the parameter you want. linkclicker you also might want to change to something more descriptive.

    You also could validate that quant is an int if that is a requirement. Don't trust that value though in your next script.

    I would probably have done this with an HTML form..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效