Javascript 如何使用jquery根据复选框状态获取隐藏字段的值

Javascript 如何使用jquery根据复选框状态获取隐藏字段的值,javascript,php,jquery,checkbox,phalcon,Javascript,Php,Jquery,Checkbox,Phalcon,我正在做一个小的phalcon项目,在一个特定的页面上有一个搜索框来搜索客户,然后搜索结果显示在foreach循环下,每个结果都有一个复选框以及一个有值的隐藏字段。单击按钮时,搜索结果显示为ajax响应。选中特定复选框时,是否仍要传递与选中复选框关联的特定隐藏字段的值。在搜索框下方,有一个表单,该表单从用户处获取输入值以及从搜索结果传递的客户名称值和id。我尝试使用jQuery脚本将隐藏字段值传递给输入字段,我仅在搜索结果为1时获得所需的输出,但当搜索结果不止一个时,则仅传递第一个隐藏字段值,即

我正在做一个小的phalcon项目,在一个特定的页面上有一个搜索框来搜索客户,然后搜索结果显示在foreach循环下,每个结果都有一个复选框以及一个有值的隐藏字段。单击按钮时,搜索结果显示为ajax响应。选中特定复选框时,是否仍要传递与选中复选框关联的特定隐藏字段的值。在搜索框下方,有一个表单,该表单从用户处获取输入值以及从搜索结果传递的客户名称值和id。我尝试使用jQuery脚本将隐藏字段值传递给输入字段,我仅在搜索结果为1时获得所需的输出,但当搜索结果不止一个时,则仅传递第一个隐藏字段值,即使我选中了第二个或第三个复选框。 我是个编程高手。请帮忙。 我的代码如下:

public function editengagementAction($id)
{
    $engmt = Engagement::findFirstById($id);
    $eid=$engmt->customerid;
    $cusdetails= Customerdetails::findFirstById($eid);
    $this->view->objs = $cusdetails;
    if(isset($_POST['searchrslt'])){
        $rst = $_POST['searchrslt'];
        $outputs = $this->db->query("SELECT * FROM customerdetails WHERE name LIKE '%".$rst."%' ")->fetchAll();

        echo"<table width='98%' class='table table-condensed' align='right' id='srchtable' ><thead>";
        echo"<tr><th class='mi_table_head'  style='padding-left:10px;'>User Name</th>";
        echo"<th class='mi_table_head'  style='padding-left:10px;'>Company Details</th>";
        echo"<th class='mi_table_head'  style='padding-left:10px;'>Email</th>";
        echo"<th class='mi_table_head'  style='padding-left:10px;'>Phone NUmber</th>";
        echo"<th class='mi_table_head'  style='padding-left:10px;'></th>";
        echo"<th class='mi_table_head'  style='padding-left:10px;'></th></tr>";
        $count=1;
        foreach ($outputs as $value) {
            echo"<tr><td height='40'  class='mi_table_text'  style='padding-left:10px;'>$value[name]</td>";
            echo"<td valign='middle' class='mi_table_text'  style='padding-left:10px;'>$value[companyname]<br>$value[companyurl]</td>";
            echo"<td valign='middle' class='mi_table_text'  style='padding-left:10px;'>$value[email]</td>";
            echo"<td valign='middle' class='mi_table_text'  style='padding-left:10px;'>$value[phonenumber]</td>";
            echo"<td valign='middle' class='mi_table_text'  style='padding-left:10px;'><input type='checkbox' name='checkbox'  id='count' value='$value[name]'></td>";
            echo"<td valign='middle' class='mi_table_text'  style='padding-left:10px;'><input type='hidden' id='$count' name='cid' value='$value[id]'></td></tr>";
            echo "<script>
            $(function(){ $('#addsubmit').on('click',function(){
             $('#checkbox').removeAttr('checked');
             var boxChecked = false;
             var customid;
             $('input[type=\"checkbox\"]').each(function() {
              if ($(this).is(':checked')) {
             boxChecked = $(this).val();
             customid=$('input[type=\"hidden\"]').val();
               alert('id is'+ customid);
               }
                });
               $('#custname').val(boxChecked);
               $('#custmid').val(cusid);
             if (boxChecked == false) {
             alert('Please select one customer');
             return false; }
             alert('Customer Changed !');
             return false;
             }); });
             </script>";
            $count++;
        }
        echo"<tr><td colspan='10' align='right'><input type='button' value='Add Customer' id='addsubmit' class='button blue' name='button' onclick='addcustmr()'></td></tr>";
        echo"</tbody><tbody><tbody><tbody></thead></table>";
        exit();
        $this->view->disable();
    }  
  }

为了获得隐藏的输入,您需要更改此行:

customid=$('input[type=\"hidden\"]').val();


使用这样的回音语句是完全疯狂的。请提供你的代码OMG。你就是那个人…它起作用了。哇,这个社区太棒了。非常感谢你。。
customid=$(this).parent().next().children('input[type=\"hidden\"]').val();