[英]How can I change read only dropdowns/text boxes to read/write depending on selection made by user?
It will have one text box (txtGRC) which will be read/write no matter what. 它将具有一个文本框(txtGRC),无论如何,该文本框都将被读取/写入。
However, I would like to have the rest of the boxes greyed out until an input has been made into txtGRC. 但是,我想将其余的框都显示为灰色,直到已向txtGRC中输入内容为止。
My problem is a bit more complicated than this but once this has been solved I believe that I can take over the rest. 我的问题要比这复杂得多,但是一旦解决,我相信我可以接管其余的工作。 It's funny, I could do this easily on VB. 很好笑,我可以在VB上轻松完成此操作。
Here is the code for the container: 这是容器的代码:
<content id="GenerateReportContent" class="col-md-4">
<form id="GenerateReportContainer">
<div class="AltFunctions">
<ul>
<li>
<a href="#" class="AltButton" id="altClearButton">Clear</a>
</li>
<li>
<a href="#" class="AltButton" id="GRaltInfoButton">Info</a>
</li>
</ul>
</div>
<h1 id="GenerateReportHeader">GENERATE REPORT</h1>
<input type="text" id="txtGRC" class="form-control" placeholder="Enter Specific Claim Number...." >
<p id="txtOptional">(optional)</p>
<select id="GRDropDown">
<option value="SelectReport">Select Report</option>
</select>
<br />
<select id="GRDropDown">
<option value="SelectSupplierName" disabled="disabled">Select Supplier Name</option>
</select>
<br />
<select id="GRDropDown">
<option value="SelectReviewPeriod" disabled="disabled">Select Review Period</option>
</select>
<div class="form-group">
<input type="text" id="txtGRC" class="form-control" placeholder="Month Code..." disabled="disabled">
<p id="txtOptional">(optional)</p>
</div>
<button type="submit" id="GenerateReportButton" class="btn btn-default">GO</button>
</form>
</content>
If you need more information just place a comment and I will do what I can. 如果您需要更多信息,请发表评论,我将尽我所能。 Thank you in advance. 先感谢您。
With javascript / jQuery, you will have to handle a keypress on that textbox, and if the length of the value of the textbox is bigger than 0, or the length you want, then, foreach other input disabled, you will enable it. 使用javascript / jQuery,您将必须处理该文本框上的按键,并且如果文本框的值的长度大于0或所需的长度,则禁用每个其他输入,则将其启用。
An example: 一个例子:
$(".txtGRC").keyup(function() {
if( $(this).length > 0 ) {
$("input.disabled").each(function() {
$(this).prop("disabled", false);
});
}
else {
$("input.disabled").each(function() {
$(this).prop("disabled", true);
});
}
});
So basically the code above (with jQuery) checks whenever the user release the key pressed and calculates the length of the textarea, if this is bigger than 0, it enables de inputs with the class ".disabled" (here you should put the inputs that starts disabled), otherwise, it disables them. 因此,基本上以上代码(使用jQuery)都在用户释放按键时进行检查,并计算文本区域的长度,如果该长度大于0,则会启用“ .disabled”类的de输入(在此处应将输入放以禁用开始),否则,将其禁用。
First, the "disabled" attribute should be applied to the "select" tag not "option". 首先,应将“已禁用”属性应用于“选择”标记而非“选项”。
<select id="GRDropDown" disabled>
Now, for your "txtGRC" field, you have three attributes to choose from (as event handlers): 现在,对于“ txtGRC”字段,您可以选择三个属性(作为事件处理程序):
depending on the browser the client will be using. 取决于客户端将使用的浏览器。
<input type="text" id="txtGRC" class="form-control" placeholder="Enter Specific Claim Number...." onkeydown="valueChanged()">
Finally, add the javascript function to disable/enable "GRDropDown" dropdowns: 最后,添加javascript函数以禁用/启用“ GRDropDown”下拉列表:
<script>
function valueChanged() {
var val = document.getElementById("txtGRC").value;
var dd = document.getElementById("GRDropDown");
if(val.length>0) dd.disabled=false;
else dd.disabled = true;
}
</script>
If you have jQuery previously included in your code, the solution would be simpler. 如果您的代码中以前包含了jQuery,则解决方案会更简单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.