admin管理员组文章数量:1321065
I have a validator in my Webform.aspx
<asp:RequiredFieldValidator ID="val1" ClientIDMode="Static" runat="server"/>
In my jquery, I have a function which attempts to disable it called by a button in the markup
btnclick = function()
{
var a = $('#val1');
alert(a); //alerts [object Object]
ValidatorEnable(a, false); //gets a console error
}
when this function is executed, I get an error in the console (I am using Google Chrome), saying that uncaught TypeError: Cannot set property 'visibility' of undefined
Is this saying that my var a is undefined? ... but that makes no sense since it is alerting an [object Object]
I also did alert(a.length
) which gave me 1
as expected.
I have a validator in my Webform.aspx
<asp:RequiredFieldValidator ID="val1" ClientIDMode="Static" runat="server"/>
In my jquery, I have a function which attempts to disable it called by a button in the markup
btnclick = function()
{
var a = $('#val1');
alert(a); //alerts [object Object]
ValidatorEnable(a, false); //gets a console error
}
when this function is executed, I get an error in the console (I am using Google Chrome), saying that uncaught TypeError: Cannot set property 'visibility' of undefined
Is this saying that my var a is undefined? ... but that makes no sense since it is alerting an [object Object]
I also did alert(a.length
) which gave me 1
as expected.
- I just had this problem yesterday and couldn't figure it out. Went with CustomValidator, that may be a viable option for you as well. – Andrew Walters Commented Mar 7, 2013 at 15:17
- @AndrewWalters I am leaning towards that however I saw that this is a viable solution. I am just confused as to why it doesn't work. – Rhs Commented Mar 7, 2013 at 15:19
-
1
Have you tried
ValidatorEnable(a[0], false)
? ValidatorEnable needs an element, not a jQuery object. – jrummell Commented Mar 7, 2013 at 15:20 - Usually the requiredfield validators don't need to be invoked with a custom javascript, they will be invoked with a submit button. Why invoke with .js? – Jon Harding Commented Mar 7, 2013 at 15:20
- @jrummell that appears to be the solution thanks! – Rhs Commented Mar 7, 2013 at 15:22
1 Answer
Reset to default 12ValidatorEnable
needs an element, not a jQuery object. You can get the first matched element using an index.
var a = $('#val1');
ValidatorEnable(a[0], false);
本文标签: javascriptEnableValidator in JSStack Overflow
版权声明:本文标题:javascript - EnableValidator in JS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741961649a2407313.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论