[英]Need to evaluate content in drop-down in Javascript
As stated in the topic I need to evaluate two fields, one from a drop-down menu item, and one for a text input type field.如主题中所述,我需要评估两个字段,一个来自下拉菜单项,另一个用于文本输入类型字段。 both in HTML of course.当然,两者都在 HTML 中。 I want to test if the fields are empty, zero, whatever in that context.我想测试这些字段是否为空、零,无论在那种情况下。
I have tried to alter the code, but cannot seem to find the right code.我试图更改代码,但似乎找不到正确的代码。
$(document).ready(function() {
$(function() {
$("#companyDialog").dialog({
autoOpen: false
});
$("#companyButton").on("click", function() {
$("#companyDialog").dialog("open");
});
});
// Validating Form Fields.....
$("#companySubmit").click(function(e) {
var comnpanyname = $("#companyname").val();
var editcompanyscombo = $("#editcompanyscombo").val();
if (companyname === '' || editcompanyscombo === '') {
alert("Please fill all fields marked with an *!");
e.preventDefault();
} else if (editcompanyscombo === '0') {
alert("Select comany to update!");
e.preventDefault();
} else {
alert("Form Submitted Successfully.");
}
});
});
<div class="container">
<div class="main">
<div id="companyDialog" title="Edit company">
<form action="" method="post">
<@@ CompanyEditCombo @@><br>
<label>New company name:</label>
<input id="companyname" name="companyname" type="text">
<input id="companySubmit" type="submit" value="Submit">
</form>
</div>
<input id="companyButton" type="button" value="Open Company Edit Dialog Form">
</div>
</div>
The fields pop up, but they do not alert if the values are zero or empty.这些字段会弹出,但如果值为零或为空,它们不会发出警报。
So far I could see from these snippets, please replace === ''
and === '0'
by == null
到目前为止,我可以从这些片段中看到,请将=== ''
和=== '0'
替换为== null
(Double equality comparison operator does not aimed to compare the types. That is why, one should use it because null
is type object
. s. Developer Mozilla ) (双重相等比较运算符的目的不是比较类型。这就是为什么应该使用它,因为null
是类型object
. s. Developer Mozilla )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.