我想从选择框中拆分值,因为我必须向客户显示总价并向管理员发送邮件。如果我不使用拆分值,那么我无法将选择选项标签发送给管理员以进行订单处理。我尽了最大的努力,但我失败了.....我再次问这个问题......请帮助我解决这个问题
<form method="post" action="" class="calc-form" enctype="multipart/form-data">
<div>
<label>Choose Currency</label>
<select id="currency" class="shopEssaySelect" name="txtCurrency" required>
<option selected disabled value="">Choose ...</option>
<option value="1/$">US Dollar</option>
<option value="3.65/Dirham">UAE Dirham</option>
</select>
</div>
<div>
<label>Type of Paper</label>
<select id="category" class="shopEssaySelect" name="txtPaperType" required>
<option selected disabled value="">Choose ...</option>
<option value="10/Paper One">Paper One</option>
<option value="10/Paper Two">Paper Two</option>
</select>
</div>
<div>
<label>Academic Level</label>
<select id="type" class="shopEssaySelect" name="txtAcademicLevel" required>
<option selected disabled value="">Choose ...</option>
<option value="50/Profesional">Profesional</option>
<option value="40/Graduate">Graduate</option>
</select>
</div>
<div>
<label>Deadline</label>
<select id="deadline" class="shopEssaySelect" name="txtDeadline" required>
<option selected disabled value="">Choose ...</option>
<option value="345/12 Days">12 Days</option>
<option value="568/3 Days">3 Days</option>
</select>
</div>
<div>
<label>Service Type</label>
<select id="servicetype" class="shopEssaySelect" name="txtServiceType" required>
<option selected disabled value="">Choose ...</option>
<option value="12/New Work">New Work</option>
<option value="4/Editing">Editing</option>
</select>
</div>
<div>
<label>Line Spacing</label>
<select id="linespacing" class="shopEssaySelect" name="txtLineSpacing" required>
<option selected disabled value="">Choose ...</option>
<option value="12/250/Dopuble Space">Double Space</option>
<option value="4/450/Single Space">Single Spacing</option>
</select>
</div>
<div>
<label>Paper Format</label>
<div class="paper-format">
<input type="radio" name="txtPaperFormat" value="MLA">MLA
<input type="radio" name="txtPaperFormat" value="APA">APA
<input type="radio" name="txtPaperFormat" value="Chicago">Chicago / Turabian
<input type="radio" name="txtPaperFormat" value="Harvard">Harvard
<input type="radio" name="txtPaperFormat" value="Other">Other
</div>
<div>
<label>Paper Details</label>
<textarea name="txtPaperDetail" required></textarea>
</div>
<div>
<label>Attachment</label>
<input type="file" name="fileatt" required />
</div>
<div>
<label>Pages</label>
<div class="numbers-row">
<input name="numberOfPages" id="numberOfPages" class="shopEssaySelect" value="0" type="text" maxlength="3" autocomplete="off" required>
</div>
<div class="word-count">Word Count<br />
<span id="totalwords">0</span></div>
</div>
<br clear="all" />
<p id="my-total">
Approximate Price: <span id="curr-symbol"></span> <span id="total">0</span></p>
<br clear="all" />
<br clear="all" />
<div>
<input type="submit" value="" class="sidebar-submitt-button-inner"/>
</div>
</div>
</form>
// jquery代码在这里
function updateTotal(){
currency = $("#currency").val();
currency_array = currency.split("/");
currency_percentage = currency_array[0];
currency_symbol = currency_array[1];
$("#curr-symbol").text(currency_symbol);
// from here split does not work
paper_values = $("#category").val();
paper_array = paper_values.split("/");
paper = paper_array[0];
type_values = $("#type").val();
type_array = type_values.split("/");
type_percentage = type_array[0];
deadline_values = $("#deadline").val();
deadline_array = deadline_values.split("/");
deadline_percentage = deadline_array[0];
service_values = $("#servicetype").val();
service_array = service_values.split("/");
service_percentage = service_array[0];
// but from here split works
spacing = $("#linespacing").val();
spacing_array = spacing.split("/");
spacing_percentage = spacing_array[0];
spacing_words = spacing_array[1];
type = (paper * type_percentage) / 100;
deadline = (paper * deadline_percentage) / 100;
servicetype = (paper * service_percentage) / 100;
linespacing = (paper * spacing_percentage) / 100;
currency = (paper * currency_percentage);
words = Number($("#numberOfPages").val());
counted_words = words * spacing_words;
$("#totalwords").text(counted_words);
total_amount = (paper + type + deadline + servicetype + linespacing + currency) * words;
if (!isNaN(total_amount)){
total_amount = Math.round((paper + type + deadline + servicetype + linespacing + currency) * words);
}
else {
total_amount ="0";
}
$("#total").text(total_amount);
}
$(".shopEssaySelect").change(function(){
updateTotal();
})
$("#numberOfPages").on("input", function(event) {
updateTotal();
})
答案 0 :(得分:0)
请尝试如下:
currency = $(&#34; #currency&#34;)。val(); currency_array = $ .trim(currency).split(&#39; |&#39;);
答案 1 :(得分:0)
如果要从选择框中选择所选值,请执行以下操作:
currency= $("#currency").find(':selected').val();
currency_array = currency.split("/");
尝试以上操作,我认为它适合您。
答案 2 :(得分:0)
试试这个fiddle:
$(document).ready(function(){
$("#currency").change(function(){
changedDD($(this).val(), "currency");
});
$("#category").change(function(){
changedDD($(this).val(), "category");
});
$("#type").change(function(){
changedDD($(this).val(), "type");
});
$("#deadline").change(function(){
changedDD($(this).val(), "deadline");
});
$("#servicetype").change(function(){
changedDD($(this).val(), "servicetype");
});
$("#linespacing").change(function(){
changedDD($(this).val(), "linespacing");
});
function changedDD(string, selectBox)
{
console.log("----------"+selectBox+"-----------");
console.log(string.substring(0, string.lastIndexOf("/")) );
console.log(string.substring(string.lastIndexOf("/") + 1, string.length));
}
});