簡體   English   中英

選中復選框時顯示文本框,並在php中發布兩個值

[英]Display the textbox when a checkbox is checked and post both the values in php

我試圖在選中復選框時顯示一個文本框。 當任何一個復選框被選中時,我都有3個復選框,以顯示該特定選中復選框的文本框。 然后,復選框的值和輸入的文本框值將通過php發送。 如何在php中顯示選中的復選框和文本框值。 我在php中發現困難,如何在php中顯示選中的復選框和特定的文本框值

這是代碼

<form action="" method="POST">
        <div id="opwp_woo_tickets">
            <input type="checkbox" class="maxtickets_enable_cb" name="opwp_wootickets[tickets][0][enable]" value="cxfdvbbxbccv">check1
            <div class="max_tickets">
                <input type="text" name="opwp_wootickets[tickets][0][maxtickets]">
            </div>

            <input type="checkbox" class="maxtickets_enable_cb" name="opwp_wootickets[tickets][1][enable]" value="xc bvcvbcvbnb">check2
            <div class="max_tickets">
                <input type="text" name="opwp_wootickets[tickets][1][maxtickets]">
            </div>

            <input type="checkbox" class="maxtickets_enable_cb" name="opwp_wootickets[tickets][2][enable]"value="cxrdyrty rty tr">check3
            <div class="max_tickets">
                <input type="text" name="opwp_wootickets[tickets][2][maxtickets]">
            </div>
         </div>
         <input type="submit" name="submit" value="submit">
        </form>
  <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

index.js

  jQuery(document).ready(function($) {
       // STOCK OPTIONS
        $('input.maxtickets_enable_cb').change(function(){
            if ($(this).is(':checked'))
        $(this).next('div.max_tickets').show();
    else
        $(this).next('div.max_tickets').hide();
        }).change();
    });

PHP

<?php
if(isset($_POST["submit"]))
{
$checkbox1=$_POST['opwp_wootickets']; 
    $chk=""; 
foreach($checkbox1 as $chk1)  
   {  
      $chk .= $chk1.",";  
   }
echo "$chk";
}

這里isAgeSelected是checkbox而txtage是inputboxtxt

if($('#isAgeSelected').checked) {
$("#txtAge").show();
} else {
 $("#txtAge").hide();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM