javascript - How to save the selected state when refreshing the php checkbox form after it is submitted
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-16 13:06:30
0
2
413
<!doctype html>

<?php
//First write the relevant calling code here


$coin = 1280;
$money = 1121;
$coinsale = $coin / 100;
if ( $_POST[ "coin" ] != 0 ) {
    $money -= $coinsale;

}

?>
<html>

<head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
</head>



<body>

    <form id="form1" name="form1" action="test.php" method="post">
        <input id="coin" name="coin" type="checkbox" value="<?php echo($coinsale)?>" onclick="checkboxOnclick(this)">Tuotecoin

        <input id="sale" type="hidden" value="<?php echo($money)?>">
        <input id="asd" type="hidden" value="<?php echo($coinsale)?>">
        <p id="npay" style="width:100%;height:95px;line-height:50px;font-weight:800;font-size:14px;color:red; text-align:center">
            ¥
            <?php echo $money; ?>
        </p>
        <input type="hidden" id="goodsmoney" name="goodsmoney" value="<?php echo $money; ?>"/>
    </form>

</body>
<script>
    

            function checkboxOnclick( checkbox ) {

                var goods = document.getElementById( "npay" );
                var m = document.getElementById( "sale" ).value;
                var c = document.getElementById( "asd" ).value;
                var f = document.getElementById( "form1" );
                if (checkbox.checked == true) {

                    m -= c;
                    goods.innerHTML = "¥" + m;
                    f.submit();
                } else {
                    goods.innerHTML = "¥" + m;
                    
                }
            }
    <!--$.("input[type='checkbox']:checked")-->
        
    
</script>

</html>

I hope you can give me a small example. I don’t know the specific implementation and I’m not familiar with PHP. Thank you everyone:)

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(2)
洪涛
  1. After submitting the form, you can get the value in the controller and pass it back

  2. Fixed location storage, eg: Add a hidden tag to the page to store the selected value, cookie

  3. Do not refresh the page, use ajax to pass the value

  4. Put an iframe on the page, copy the form to the iframe, and submit it

Peter_Zhu

$.("input[type='checkbox']:checked") After getting the value, you can put it in the cookie. Every time you refresh the page, first get the value in the cookie, and then use .each to loop through the effect. Come out

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template