在一个页面中选中一个复选框 自动选择 在另一个页面中使用 PHP,JavaScript


select a checkbox in one page automatically select in another page using php,javascript

我设计了 2 个 html 页面,在这里我找到一些相同的代码用于 2 页中的复选框.我想要这个,当我在第一页选中复选框时,然后自动选中第 2 页中的相同复选框.我该怎么做?

我的 2 页 CHK 框代码

您想将其提供给其他人复制吗?

是的

让这个成为你的 html 表单。

<form action="your/action" method="POST" name="form">
      <input type="checkbox" name="postCheckBox" value=""/>
<input type="submit" value="submit"/>
</form>

在/your/action.php 页面

$_SESSION['postCheckBox'] = isset($_POST["postCheckBox"]) ? $_POST["postCheckBox"] : null;

在下一个 html 页面中:

<input type="checkbox" name="somename" <?php echo isset($_SESSION['postCheckBox']) && $_SESSION['postCheckBox'] == 1 ? 'checked="true": ""' ?>value=""/>
我相信最简单的

方法是简单地在会话中添加一个值并在另一页上阅读它。

Checkbox will select automatically perticular checkboxes from selected price list of home page.
    $("input[name=categories]").each( function (index) {    
        iterations = $.cookie('total_iterations');
        var orgval = $(this).val();
        for (var i = 1; i <= iterations; i++) {
            var chkval =$.cookie("plan_item_cookie_cb_"+i);
            if(chkval.trimRight() == orgval )
            {
                $(this).prop('checked', true);
            }
       };
    });
    $('#plan_section_id_1').click(function(){
        var cookies = $.cookie();
        for(var cookie in cookies) {
           $.removeCookie(cookie);
        }
        var count=0;
        //alert('outside');
        $('#plan_section_id_1').find('input[type="hidden"]').each(function(){
            //alert('in');
            its = $('#plan_section_id_1 .total_iterations').val();
            if ($(this).val().length) {
            //if ($.trim($(this).val()).length) {
                count++;
                $.cookie('plan_item_cookie_cb_'+count,decodeURI($(this).val()),60);
                //$.cookie('section-id','plan_section_id_1');
                $.cookie('total_iterations',its);
            }
        });
    });
    $('#plan_section_id_2').click(function(){
        var cookies = $.cookie();
        for(var cookie in cookies) {
           $.removeCookie(cookie);
        }
        var count=0;
        $('#plan_section_id_2').find('input[type="hidden"]').each(function(){
            its = $('#plan_section_id_2 .total_iterations').val();
            if ($(this).val().length) {
            //if ($.trim($(this).val()).length) {
                count++;
                $.cookie('plan_item_cookie_cb_'+count,decodeURI($(this).val()),60); 
                $.cookie('total_iterations',its);
            }
        });
    });
    $('#plan_section_id_3').click(function(){
        var cookies = $.cookie();
        for(var cookie in cookies) {
           $.removeCookie(cookie);
        }
        var count=0;
        $('#plan_section_id_3').find('input[type="hidden"]').each(function(){
            its = $('#plan_section_id_3 .total_iterations').val();
            if ($(this).val().length) {
            //if ($.trim($(this).val()).length) {
                count++;
                $.cookie('plan_item_cookie_cb_'+count,decodeURI($(this).val()),60);
                $.cookie('total_iterations',its);
            }
        });
    });