0

我有一个名为 sendform.php 的文件,其中包含一个 POST 数据并通过邮件发送的表单。

现在我有一个 JavaScript 函数,可以将 4 个不同选择字段的选择选项相乘。

        <script language="javascript">
        function Calculate()
        {
            var h = document.getElementById('bedrag-bol').value;
            var l = document.getElementById('aantal-bol').value;
            var h2 = document.getElementById('bedrag-gamma').value;
            var l2 = document.getElementById('aantal-gamma').value;
            var h3 = document.getElementById('bedrag-douglas').value;
            var l3 = document.getElementById('aantal-douglas').value;
            var h4 = document.getElementById('bedrag-bartsmit').value;
            var l4 = document.getElementById('aantal-bartsmit').value;
            var result = h * l * 10 + h2 *l2 * 10 + h3 * l3 * 10 + h4 * l4 * 10;
            document.getElementById('totaal').innerHTML = result;
        }
    </script>
                    <form name="aanvraag" method="post" action="index.php?p=<?php echo $_GET['p']; ?>&amp;action=checkform">
                    <table width="700" cellpadding="3" cellspacing="3">
    <tr>
        <td><img src="bestanden/spaaractie/bol.png"  /></td>
        <td><img src="bestanden/spaaractie/gamma.png"  /></td>
        <td><img src="bestanden/spaaractie/douglas.png"  /></td>
        <td><img src="bestanden/spaaractie/bartsmit.png"  /></td>
    </tr>
    <tr>
        <td><select id="bedrag-bol" name="bedrag-bol" onChange="Calculate();">
                <option value="0" selected="selected">Kies uw bedrag</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bol']) == "5") {echo "selected='selected'"; } ?>>&euro; 5,00</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bol']) == "10") {echo "selected='selected'"; } ?>>&euro; 10,00</option>
                <option value="25" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bol']) == "25") {echo "selected='selected'"; } ?>>&euro; 25,00</option>
                <option value="50" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bol']) == "50") {echo "selected='selected'"; } ?>>&euro; 50,00</option>
            </select>
        </td>
        <td><select id="bedrag-gamma" name="bedrag-gamma" onChange="Calculate();">
                <option value="0" selected="selected">Kies uw bedrag</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-gamma']) == "5") {echo "selected='selected'"; } ?>>&euro; 5,00</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-gamma']) == "10") {echo "selected='selected'"; } ?>>&euro; 10,00</option>
                <option value="25" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-gamma']) == "25") {echo "selected='selected'"; } ?>>&euro; 25,00</option>
                <option value="50" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-gamma']) == "50") {echo "selected='selected'"; } ?>>&euro; 50,00</option>
            </select>
        </td>
        <td><select id="bedrag-douglas" name="bedrag-douglas" onChange="Calculate();">
                <option value="0" selected="selected">Kies uw bedrag</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-douglas']) == "10") {echo "selected='selected'"; } ?>>&euro; 10,00</option>
                <option value="25" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-douglas']) === "25") {echo "selected='selected'"; } ?>>&euro; 25,00</option>
                <option value="50" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-douglas']) == "50") {echo "selected='selected'"; } ?>>&euro; 50,00</option>
            </select>
        </td>
        <td><select id="bedrag-bartsmit" name="bedrag-bartsmit" onChange="Calculate();">
                <option value="0" selected="selected">Kies uw bedrag</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bartsmit']) == "5") {echo "selected='selected'"; } ?>>&euro; 5,00</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bartsmit']) === "10") {echo "selected='selected'"; } ?>>&euro; 10,00</option>
                <option value="25" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bartsmit']) == "25") {echo "selected='selected'"; } ?>>&euro; 25,00</option>
                <option value="50" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['bedrag-bartsmit']) == "50") {echo "selected='selected'"; } ?>>&euro; 50,00</option>
            </select>
        </td>
    </tr>
    <tr>
        <td><select id="aantal-bol" name="aantal-bol" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bol']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
        <td><select id="aantal-gamma" name="aantal-gamma" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-gamma']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
        <td><select id="aantal-douglas" name="aantal-douglas" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-douglas']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
        <td><select id="aantal-bartsmit" name="aantal-bartsmit" onChange="Calculate();">
                <option value="0" selected="selected">Kies het aantal</option>
                <option value="1" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "1") {echo "selected='selected'"; } ?>>1</option>
                <option value="2" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "2") {echo "selected='selected'"; } ?>>2</option>
                <option value="3" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "3") {echo "selected='selected'"; } ?>>3</option>
                <option value="4" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "4") {echo "selected='selected'"; } ?>>4</option>
                <option value="5" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "5") {echo "selected='selected'"; } ?>>5</option>
                <option value="6" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "6") {echo "selected='selected'"; } ?>>6</option>
                <option value="7" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "7") {echo "selected='selected'"; } ?>>7</option>
                <option value="8" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "8") {echo "selected='selected'"; } ?>>8</option>
                <option value="9" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "9") {echo "selected='selected'"; } ?>>9</option>
                <option value="10" <?php if(isset($_POST['Submitform']) && strip_tags($_POST['aantal-bartsmit']) == "10") {echo "selected='selected'"; } ?>>10</option>
            </select>
        </td>
    </tr>
</table>
<div style="margin-left:15px; margin-top:20px;"><span id="totaal" style="color:#F00;">0</span></div>
                        
                        <div id="fm-submit">
                            <input name="Submitform" value="Verstuur" type="submit" />
                        </div>
                

</form> 

是否可以使用 PHP 发布 JavaScript 变量?我找到了一些关于它的文章,我知道这是可能的,但我无法弄清楚。

4

2 回答 2

0

谢谢大家的回复

这成功了:

Javascript:

document.aanvraag.totaal.value = result; //assign value to hidden input element.

html

<input type="hidden" name="totaal" id="totaal" value="" />

@Christoph 谢谢!:)

于 2013-09-27T12:35:50.167 回答
0

见表格

 <form name="aanvraag" method="post" action="" onsubmit="Calculate()">

在此处编写所有 HTML 并包含隐藏字段

<input type="hidden" name="totaal" id="totaal" value="" />

<input name="Submitform" value="Verstuur" type="submit" />

</form>

当您提交此表单时,在提交之前,表单计算函数将调用并将总值粘贴到隐藏字段中,然后将所有值与您的给定 URL 一起发布。

于 2013-09-27T12:49:35.483 回答