douran9707 2016-12-05 04:53
浏览 46

如何在提交表单之前禁用循环中的复选框

I got a loop of checkboxes. I put a hidden field inside with different value and different id:

<form>
<?php 
    for($y=0;$y<$len;$y++)
    {   
        echo "<div class='proc'> <pre>";
        echo "<h6 >Process: ".$proc[$y]."      "   ;
        echo "People required: ".$num[$y].".      ";    
        echo "<span class='assigned' name='assigned[]' >People Assigned: 0. </span>    <input id='unchecked' type='hidden' name='link[]' value='0'/><input id='checked' type='checkbox' name='link[]' value='1'><i title='Activate Process' class='fi-link'></i>Link Process</input></h6></pre>";
?>
<div class="procLeader">
<label>Leader:</label>  
    <ol>
        <li class="placeholder"><div class="adding">Drop Here</div></li>
    </ol>
</div>              
<?php       
    echo "</div>";                      
    }
?>  

<input type = "submit" style="margin-left:300px; width:150px;" id="savebutton" name ="submit" class="button" value = "Create Project" onclick="userSubmitted = true;"/>         
</fieldset>
</form>

What I want is to submit empty checkboxes also. and if user doesnt tick it set process column to 0 in database, and if ticks to 1. The problem is form sending both variables 1 and 0 if i tick the box. I tried to disable the one boxes which are ticked in javascript:

$(document).ready(function () {
    if(document.getElementById("checked").checked) {
    document.getElementById('unchecked').disabled = true;
    }   
}); 

But I still got both values. Is there a way to disable hidden inputs if checkboxes are checked?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度