javascript - html embeds PHP code, click checkbox to change php variables and then output
滿天的星座
滿天的星座 2017-05-16 13:08:34
0
1
545
<?php
$coin=1280;
$money=1121;
$coinsale=$coin/100;

?>
    
        <input id="money" type="hidden" value="<?php echo $money?>">
        <input id="coin" type="checkbox" value="<?php echo $coinsale?>" onclick="checkboxOnclick(this)">asdsa<br>
        <input id="salemoney" type="txt" style="border: none" readonly="true" ><?php echo $money?>
</body>
<script type="text/javascript">
    function checkboxOnclick(checkbox) {
    
    var num1=document.getElementById("money").value;
    var num2=document.getElementById("coin").value;
            var num3=num1-num2;
        
    if (checkbox.checked == true){

    
    document.getElementById("salemoney").value=num3;

}else{
    document.getElementById("salemoney").value=num1;
    
}
    }
</script>

This can only change the text of the Txt text box, but cannot actually change the PHP output value
I tried putting the CheckBox in the form submission and gave my own PHP judgment, but I didn't get it
I would like to ask you how to do it Thank you for this

滿天的星座
滿天的星座

reply all(1)
给我你的怀抱

Just write an ajax interface in the background.
ajax I won’t write it, if you don’t know how to Google it yourself.

public function returnSaleMoney(){
$num1 = $_POST[''];
$num2 = $_POST[''];

$res = '自己写计算方法';

echo json_encode($res);
}

Personally, if you want to change the output value here, it is more appropriate to use js to handle it.

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