drg14799 2017-03-27 20:37
浏览 40
已采纳

价值总是一定数量

The value of my id is always 10 ( the last number in my array).

This works fine for my jQuery function, but when using it with the value attribute: it always gives me 10 when doing the get request.

When inspecting my website : value is ok!
enter image description here

When doing a var dump : notice the second value.
enter image description here

I really need this to work to get to the other page.
I'm a bit stucked.

foreach ($data as $key => $value)
{

  if ($count % 4 == 0 && $count != 0)
  {
    echo "<div class=\"container\">";
    echo "<div class=\"row\">";
    echo "</div>";
    echo "</div>";
    echo "<br> <br>";
  }

  $id = $value['id'];
  echo "<div class=\"col-sm-3\">";
  echo "<form method='get' action='..\product\details' class='product-form'>";
  $img = $value["img"];
  $category = $value["category"];
  echo "<div class='panel panel-primary $category' >";
  echo "<div class='panel-heading'>".$value["name"]."</div>";
  echo "<div class='panel-body'><img src='../../public/img/$img' class='img-responsive' style='width:100%' alt='Image'></div>";
  echo " <div class=\"panel-footer\">".$value["description"]."<br><button type='button' class='btn btn-default cart-button'  onclick='addToCart($id)'><span class='glyphicon glyphicon-shopping-cart'></span></button></div>";
  echo "<input type='hidden' name='itemid' value='$id'>";
  echo "</form>";
  echo "</div>";
  echo "</div>";

    $count++;
}

To submit the form I use this:

$(function () {
    $(".col-sm-3").click(function test(event) {
        $(".product-form").submit();
    })
})
  • 写回答

1条回答 默认 最新

  • dongqie7806 2017-03-28 01:48
    关注

    Your server side code emits several forms, one per row.

    Your jquery will attempt to submit every form that has a CSS class of ".product-form", which means all of them. Each submit will cancel the previous (on most browsers, anyway), so the server only receives a request for the last one.

    I think you only want to submit one form-- the form that is a child of the DIV being clicked. So change your jquery:

    $(function () {
        $(".col-sm-3").click(function test(event) {
            $(this).find(".product-form").submit();
        })
    })
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 php 将rtmp协议转hls协议,无法播放
  • ¥15 miniconda安装不了
  • ¥20 python代码编写
  • ¥20 使用MPI广播数据遇到阻塞
  • ¥15 TinyMCE如何去掉自动弹出的“链接…”工具?
  • ¥15 微信支付转账凭证,如何解决
  • ¥15 在win10下使用指纹登录时,界面上的文字最后一个字产生换行现象
  • ¥20 使用AT89C51微控制器和MAX7219驱动器来实现0到99秒的秒表计数,有开始和暂停以及复位功能,下面有仿真图,请根据仿真图来设计c语言程序
  • ¥15 51单片机 双路ad同步采样
  • ¥15 使用xdocreport 生成word