我创建了一个新表单。虽然onchange" systemUpdate"似乎工作正常,提交表格后发布到电子邮件,电子邮件显示以前选择的选项值,在提交表单之前已更改和更新。
例如,用户选择selectedIndex == 1,选项值" PS / 2连接" (#Wyse_Terminal div),然后改变主意并选择selectedIndex == 2并提交," PS / 2连接"仍显示在电子邮件中。
如何清除之前选择的选项值,以便它们不会在电子邮件中结束?有一个合理数量的代码,所以只包括相关的脚本和HTML
function systemUpdate(detail) {
if (detail.selectedIndex == 0) {
$("#Option_Terminal").hide();
$("#Wyse_Terminal select").removeAttr("class");
$("#Wyse_LaptopDesktop").hide();
$("#Wyse_LaptopDesktop select").removeAttr("class");
$("#HP_Terminal").hide();
$("#HP_Terminal select").removeAttr("class");
} else if (detail.selectedIndex == 1) {
$("#Wyse_Terminal").show();
$("#Wyse_Terminal select").addClass("required");
$("#Wyse_LaptopDesktop").show();
$("#Wyse_LaptopDesktop select").addClass("required");
$("#HP_Terminal").hide();
$("#HP_Terminal select").removeAttr("class");
} else if (detail.selectedIndex == 2) {
$("#Wyse_Terminal").hide();
$("#Wyse_Terminal select").removeAttr("class");
$("#Wyse_LaptopDesktop").show();
$("#Wyse_LaptopDesktop select").addClass("required");
$("#HP_Terminal").hide();
$("#HP_Terminal input").removeAttr("class");
} else if (detail.selectedIndex == 3) {
$("#Wyse_Terminal").hide();
$("#Wyse_Terminal select").removeAttr("class");
$("#Wyse_LaptopDesktop").hide();
$("#Wyse_LaptopDesktop select").removeAttr("class");
$("#HP_Terminal").show();
$("#HP_Terminal select").addClass("required");
}}
<form method="POST" title="myForm" id="myForm" name="myForm" action="emailTemplate.php">
<fieldset>
<legend>Select Your System</legend>
<p><label>Please select your system</label>
<select id="select_system" name="select_system" class="required" onchange="systemUpdate(this);">
<option value="">Select...</option>
<option value="Wyse Terminal">Wyse Terminal</option>
<option value="Laptop/Desktop">Laptop/Desktop</option>
<option value="HP Terminal">HP Terminal</option>
</select> *
<p><img style="width: 611px;"src="images/systemtype.jpg"/></p>
</p>
<br />
<div id="Wyse_Terminal">
<p><label>Please select connection type</legend>
<select id="Connection_Type" name="Connection_Type" class="required">
<option value="">Select...</option>
<option value="PS/2 connections">PS/2 connections</option>
<option value="USB connections">USB connections</option>
</select> *
<p><img style="width: 611px;"src="images/mouse.png"/></p>
</p>
</div>
<br />
<div id="Wyse_LaptopDesktop">
<p><label>Select items required</label>
<select id="Items_Required" name="Items_Required" class="required">
<option value="">Select...</option>
<option value="Keyboard and Mouse ($60)">Keyboard and Mouse ($60)</option>
<option value="Keyboard only ($40)">Keyboard only ($40)</option>
<option value="Mouse only ($20)">Mouse only ($20)</option>
</select> *
</p>
</div>
<div id="HP_Terminal">
<p><label>If HP Terminal</label>
<select id="HPTerminal" name="HPTerminal" class="required">
<option value="">Select...</option>
<option value="Wireless Keyboard and Mouse ($60)">Wireless Keyboard and Mouse ($60)</option>
</select> *
</p>
</div>
</fieldset>
<fieldset id="yourDetails">
</fieldset>
<p class="submit"><input class="button" onClick="return checkTicked();" name="Submit" type="submit" value="Submit"></p>
感谢您帮助新手!
答案 0 :(得分:0)
试试这个
function systemUpdate(detail) {
if (detail.selectedIndex == 0) {
$("#Option_Terminal").hide();
$("#Option_Terminal").val("");
$("#Wyse_Terminal select").removeAttr("class");
$("#Wyse_LaptopDesktop").hide();
$("#Wyse_LaptopDesktop").val("");
$("#Wyse_LaptopDesktop select").removeAttr("class");
$("#HP_Terminal").hide();
$("#HP_Terminal").val("");
$("#HP_Terminal select").removeAttr("class");
} else if (detail.selectedIndex == 1) {
$("#Wyse_Terminal").show();
$("#Wyse_Terminal select").addClass("required");
$("#Wyse_LaptopDesktop").show();
$("#Wyse_LaptopDesktop select").addClass("required");
$("#HP_Terminal").hide();
$("#HP_Terminal").val("");
$("#HP_Terminal select").removeAttr("class");
} else if (detail.selectedIndex == 2) {
$("#Wyse_Terminal").hide();
$("#Wyse_Terminal").val("");
$("#Wyse_Terminal select").removeAttr("class");
$("#Wyse_LaptopDesktop").show();
$("#Wyse_LaptopDesktop select").addClass("required");
$("#HP_Terminal").hide();
$("#HP_Terminal").val("");
$("#HP_Terminal input").removeAttr("class");
} else if (detail.selectedIndex == 3) {
$("#Wyse_Terminal").hide();
$("#Wyse_Terminal").val("");
$("#Wyse_Terminal select").removeAttr("class");
$("#Wyse_LaptopDesktop").hide();
$("#Wyse_LaptopDesktop").val("");
$("#Wyse_LaptopDesktop select").removeAttr("class");
$("#HP_Terminal").show();
$("#HP_Terminal select").addClass("required");
}}