javaScript用于基于文本更改的下拉更改 [英] javaScript for drop down change based on text change
问题描述
我有一个静态下拉列表
。我需要在文本更改事件上更改下拉列表
的值。
文本框
( textPaid)和下拉列表( ddlPaymentStatus
)放在网格中。
所以,请提供一个javaScript解决方案来处理这个问题。
提前致谢。
例如:。如果在文本框()中输入金额,则下拉()中的值将被更改为paid()..下拉列表的静态值(打开,支付,待定,提前)
Hi,
I have one static dropdown
. I need to change the value of dropdown
on text change event.
The textbox
(textPaid) and the drop down(ddlPaymentStatus
) are placed inside a grid.
So, please give a javaScript solution to handle this.
Thanks in advance.
Eg: .if the amount is entered in text box() ,then the value in drop down() shld be changed as paid().. the static value of dropdown(open,paid, pending ,advance)
推荐答案
我为你解决了这个问题。看看代码。
JavaScript代码
I worked this out for you. Take a look at the code.
JavaScript code
<script type="text/javascript">
// Function is used to select the DropDown Paid value
// if textbox contains any value.
function SelectPaidValue() {
// Get the controls.
var textPaid = document.getElementById('<%=textPaid.ClientID%>');
var ddlPaymentStatus = document.getElementById("<%=ddlPaymentStatus.ClientID %>");
// Check if data is there in textbox or not
if (textPaid.value != "" && textPaid.value != null) {
// If data is there select "Paid" from DropDownList.
selectItemByValue(ddlPaymentStatus, 1);
}
else {
// If data is not there, then select "--Select--" from DropDownList.
selectItemByValue(ddlPaymentStatus, 4);
}
}
// Function is used to select the DropDown option by value.
function selectItemByValue(elmnt, value) {
// Loop through all the options and select the provided value.
for (var i = 0; i < elmnt.options.length; i++) {
if (elmnt.options[i].value == value)
elmnt.selectedIndex = i;
}
}
</script>
aspx代码
aspx code
<asp:TextBox ID="textPaid" runat="server" onblur="SelectPaidValue()"></asp:TextBox>
<asp:DropDownList ID="ddlPaymentStatus" runat="server">
<asp:ListItem Value="4">--Select--</asp:ListItem>
<asp:ListItem Value="0">Open</asp:ListItem>
<asp:ListItem Value="1">Paid</asp:ListItem>
<asp:ListItem Value="2">Pending</asp:ListItem>
<asp:ListItem Value="3">Advance</asp:ListItem>
</asp:DropDownList>
谢谢......
Thanks...
试试这个
Try this
<script type="text/javascript">
function SomeFunction() {
var txt= document.getElementById('<%=Test.ClientID%>');
if(txt.value !="")
{
var x=document.getElementById("<%=dropdownid.ClientID %>");
x.selectedIndex =1;
}
}
</script>
<asp:TextBox ID="TextBox1" runat="server" onchange="SomeFunction()"></asp:TextBox>
解决方案是:
Solution is:
protected void ddlPaymentStatus_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddl = (DropDownList)sender;
GridViewRow row = (GridViewRow)ddl.NamingContainer;
int rowIndex = row.RowIndex;
DropDownList DrpLocation1 = (DropDownList)row.FindControl("DrpLocation");
TextBox textPaid1= (TextBox)row.FindControl("textPaid");
textPaid1=DrpLocation1.text;
}
如果我的答案是对的,请接受。
Please Accept if my answer is right.
这篇关于javaScript用于基于文本更改的下拉更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!