简体   繁体   English

如何回显Javascript函数的总和?

[英]How to echo a sum of a Javascript function?

So I've got this Example for you: 因此,我为您准备了以下示例:

http://jsfiddle.net/mwpmk9kk/1/ http://jsfiddle.net/mwpmk9kk/1/

As you can see, i summarize the Values of all checkboxes into one readonly input field. 如您所见,我将所有复选框的值汇总到一个只读输入字段中。

Now i want to echo the Value of all selected Checkboxes into an .php-Site after submitting it (method="post"). 现在,我想在提交后将所有选定复选框的值回显到.php-Site中(method =“ post”)。

I already tried it with echo $_POST['price']; 我已经用echo $_POST['price'];了尝试echo $_POST['price']; but that did not work. 但这没有用。

Thank you in advance 先感谢您

Try this: 尝试这个:

<?php
print "CONTENT_TYPE: " . $_SERVER['CONTENT_TYPE'] . "<BR />";
$data = file_get_contents('php://input');
print "DATA: <pre>";
var_dump($data);
var_dump($_POST);
print "</pre>";
?>

If the raw input ($data) is not empty have a look at your php.ini and check these paramters 如果原始输入($ data)不为空,请查看您的php.ini并检查这些参数

enable_post_data_reading    "1" PHP_INI_PERDIR  Available since PHP 5.4.0
post_max_size   "8M"    PHP_INI_PERDIR  PHP_INI_SYSTEM in PHP <= 4.2.3. Available since PHP 4.0.3.

A frequent error is post_max_size=x MB instead of post_max_size=x M 常见错误是post_max_size = x MB而不是post_max_size = x M

Try this... I've tested in a self submitting form like below and the $_POST['price'] is showing the value of the price in the text field. 尝试一下...我已经以如下所示的自我提交形式进行了测试,并且$ _POST ['price']在文本字段中显示了价格的值。

<?php 
    if(isset($_POST['price'])){print_r($_POST['price']); }
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="checkbox" id="cb0" onclick="UpdateCost()" name="Example1" value="5"> Text 1<br />
<input type="checkbox" id="cb1" onclick="UpdateCost()" name="Example2" value="10"> Text 2<br />
<input type="checkbox" id="cb2" onclick="UpdateCost()" name="Example3" value="15"> Text 3<br />
<input type="checkbox" id="cb3" onclick="UpdateCost()" name="Example4" value="20"> Text 4<br />
<input type="checkbox" id="cb4" onclick="UpdateCost()" name="Example5" value="25"> Text 5<br />
<input type="checkbox" id="cb5" onclick="UpdateCost()" name="Example6" value="30"> Text 6<br /><br />

<input type="text" id="totalcost" name="price" placeholder="Price" readonly size="5" value="">
<input type="submit" value="submit" name="submit" />
</form>

hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM