douhuo0884 2016-12-30 08:44
浏览 68
已采纳

传递check复选框的值并显示数组上的第一个值

I need help on my php program.

I have 2 forms inside my testing.php

  • Main form named "mainform"
  • the other Form is with checkbox named "modalForm"

My program works like this. If you click the disabled textbox, a modal will pop-up containing the form with checkbox. If only 1 of the checkbox were check I'm gonna display the textlabel of it on my disabled textbox otherwise if more than 2 were check I will display the value "Multiple" on the disabled textbox.

In short I will display only the textlabel on UI while its value will be inserted/updated into the system database.

I tried lots of condition and still i dont get it. anyone help me please.

Here is my look a like code

testing.php

<form method="post" name="mainform" action="">
        <label>TestLabel</label>
        <a href="#modal"> <!-- when the input textbox was clicked, modal will pop up -->
            <input disabled type="text" name="test" placeholder="test" value="">
        </a>
    </form>

    <form method="post" name="modalForm" id="modalForm" action="testing.php">
        <div class="modalwrapper" id="modal">   <!-- modal -->
                <div class="modalcontainer">    
                    <div class="modalcol1">
                        <label>Test 1</label>
                        <input type="checkbox" name="test_modal[]" value="mark">
                        <div class="clear"></div>
                        <label>Test 2</label>
                        <input type="checkbox" name="test_modal[]" value="joe">
                        <div class="clear"></div>
                        <label>Test 3</label>
                        <input type="checkbox" name="test_modal[]" value="kevin">
                        <div class="clear"></div>
                        <label>Test 4</label>
                        <input type="checkbox" name="test_modal[]" value="michael">
                        <div class="clear"></div>
                        <label>Test 5</label>
                        <input type="checkbox" name="test_modal[]" value="jordan">
                        <div class="clear"></div>

                        <div class="savebutton">
                            <input class="btn1" type="submit" value="Submit"/>
                        </div>
                    </div>
                </div>
            <div class="overlay"></div>
        </div>      
    </form>

styles.css

/* modal layout */
    .modalwrapper {
        top: 0;
        left: 0;
        opacity: 0;
        position: absolute;
        visibility: hidden;
        box-shadow: 0 3px 7px rgba(0,0,0,.25);
        box-sizing: border-box;
        transition: all .4s ease-in-out;
        -webkit-transition: all .4s ease-in-out;
        -moz-transition: all .4s ease-in-out;
    }

    .modalwrapper:target {
        opacity: 1;
        visibility: visible
    }

    .overlay {
        background-color: #000;
        background: rgba(0,0,0,.8);
        height: 100%;
        left: 0;
        position: fixed;
        top: 0;
        width: 100%;
        z-index: 1;
    }

    .modalcontainer {
        display: table;
        background-color: #777;
        position: relative;
        z-index: 100;
        color: #fff;
        padding: 5px;
    }

    .modalcol1 { display: table-cell; }

    .clear { clear: both; }

    .modalwrapper input[type=checkbox] {
        float: right;
        margin-right: 20px;
    }

    .savebutton input[type=submit] {
        float: right;
        background-color: maroon;
        color: #fff;
        border: none;
        padding: 5px 10px;
        margin-top: 5px;
        margin-right: 20px;
    }
    /* modal layout ends here */

Hope you guys can help me. I wanna know how can I pass the value of the checkboxes on my mainform . Thank you so much in advance.

  • 写回答

3条回答 默认 最新

  • douningchang3610 2016-12-30 11:50
    关注

    I tried that code,set id="submit" at the submit button of the modal form and id="test_modal[]" at checkboxes,I used some functions of jquery I set at header the <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

     <script type="text/javascript">
        $(document).ready(function(){
        $("#submit").click(function(e) {
    
          //  var checked = [];
            i=0;
            temp=""
    $("input[name='test_modal[]']:checked").each(function ()
    {   temp=$(this).val();
        i++;
       // checked.push($(this).val());
    });
    if (i==1)
          $("#test").val(temp);        
      else if (i>1)
          $("#test").val('multiple');
                     $("#modal").fadeOut();  
                    // alert($("#do").val())
        e.preventDefault();
    });
    });</script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿