当文本框更改事件完成时,选中grdivew中的复选框 [英] Check a checkbox in grdivew when Textbox change event is completed
问题描述
嗨朋友们,
我有一个ajax日历扩展程序和显示所选日期的文本框,最初是在日期改变的时候我是raavascript一个javascript到更改Text forecolor,以便用户可以知道他/她已更改的日期
但新要求是使用复选框
有人可以帮忙告诉我,当文本框值改变时如何实现复选框检查
以下是代码示例
Grdiview示例示例项目列我在哪里调用javascript
< ItemTemplate >
< asp:标签 ID = lblProjectStartDate runat = server 文字 =' <% #Bind( StartDate)%>'
< span class =code-attribute> 可见 = false < span class =code-keyword>> < / asp:Label < span class =code-keyword>>
< asp:CheckBox ID = chkProjectStartDate 已启用 = true runat = 服务器跨度> 已选中 =' <%#(((bool)(Eval( IsProjectDate)))? (bool) false :( bool) true )%>' / >
< asp:TextBox ID = txPrjStartDate runat = server contentEditable = false BorderStyle = 没有ne
< span class =code-attribute> < span class =code-attribute> CssClass = tm-text Text =' <% #Bind(< span class =code-string> StartDate)%>' 可见 = true 宽度 = 82px
< span class =code-attribute> onchange = txtChange('<% = chkProjectStartDate .ClientID%>'); > < / asp:TextBox >
< asp:ImageButton ID = imgProjectStartDate runat = server 高度 = 20px ImageUrl = 〜/ Images / Shared / icon_calendar.jpg
< span class =code-attribute> < span class =code-attribute> < span class =code-attribute> 宽度 = 20px / >
< asp:CalendarExtender ID = calPrjStartDate runat = 服务器 已启用 = True 格式 = < span class =code-keyword> dd / MM / yyyy
< span class =code-attribute> PopupButtonID = imgProjectStartDate TargetControlID = txPrjStartDate >
< / asp:CalendarExtender >
< asp:RequiredFieldValidator ID = rfSTDate runat = server ControlToValidate = txPrjStartDate
< span class =code-attribute> < span class =code-attribute> CssClass = 强制性 显示 = 动态 ErrorMessage = required ValidationGroup = SavePS > < / asp:RequiredFieldValidator >
< / ItemTemplate >
JavaScript代码
< < span class =code-leadattribute> script type = text / javascript >
function txtChange( chkCheckbox){
chkCheckbox.checked = true;
}
< / script >
试试这个
< script 类型 = text / javascript >
function txtChange(chkCheckbox){
< span class =code-keyword> var td = chkCheckbox.offsetParent;
var inputs = td.getElementsByTagName( 输入跨度>);
for ( var i = 0 ; i< inputs.length; i ++){
if (inputs [i] .type == ' 复选框'){
inputs [i] .checked = true ;
break ;
}
}
}
< / script >
onchange =txtChange(this);
Hi Friends ,
I have a ajax calendar extender and the textbox where the selected date is shown , initially when the date was change I was rasising a javascript to change the Text forecolor , so that user can know which dates he/she has change
but the new requirement is to use the checkbox
can anyone please assist to tell me , how can I achieve a checkbox check when textbox box value is change
below is the code for example
Grdiview example sample item column where I am calling javascript
<ItemTemplate>
<asp:Label ID="lblProjectStartDate" runat="server" Text='<%# Bind("StartDate") %>'
Visible="false"></asp:Label>
<asp:CheckBox ID="chkProjectStartDate" Enabled="true" runat="server" Checked='<%# (((bool)(Eval("IsProjectDate"))) ? (bool)false: (bool)true ) %>' />
<asp:TextBox ID="txPrjStartDate" runat="server" contentEditable="false" BorderStyle="None"
CssClass="tm-text" Text='<%# Bind("StartDate") %>' Visible="true" Width="82px"
onchange="txtChange('<%= chkProjectStartDate.ClientID%>');"></asp:TextBox>
<asp:ImageButton ID="imgProjectStartDate" runat="server" Height="20px" ImageUrl="~/Images/Shared/icon_calendar.jpg"
Width="20px" />
<asp:CalendarExtender ID="calPrjStartDate" runat="server" Enabled="True" Format="dd/MM/yyyy"
PopupButtonID="imgProjectStartDate" TargetControlID="txPrjStartDate">
</asp:CalendarExtender>
<asp:RequiredFieldValidator ID="rfSTDate" runat="server" ControlToValidate="txPrjStartDate"
CssClass="mandatory" Display="Dynamic" ErrorMessage="required" ValidationGroup="SavePS"></asp:RequiredFieldValidator>
</ItemTemplate>
JavaScript code
<script type="text/javascript">
function txtChange(chkCheckbox) {
chkCheckbox.checked = true;
}
</script>
Try this
<script type="text/javascript"> function txtChange(chkCheckbox) { var td = chkCheckbox.offsetParent; var inputs = td.getElementsByTagName("input"); for (var i = 0; i < inputs.length; i++) { if (inputs[i].type == 'checkbox') { inputs[i].checked = true; break; } } } </script>
onchange="txtChange(this);
这篇关于当文本框更改事件完成时,选中grdivew中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!