The problem is that when user checked the "One way" the Return Date text box should be disabled. I disabled it but the Required field validator raises. And when i tried to disable the Required Field Validator an error occurred
"Microsoft JScript runtime error: Unable to set value of the property 'disabled': object is null or undefined"
Please Guide me how to solve this. I tried following :
The best option in this scenario is to create a custom validator and in validation function, check if one way is checked then return date text could be blank else it should be entered etc....
if u only want to use requiredfieldvalidator, then try this code to disable the requiredfield validator.
dpkchhirang
Member
199 Points
164 Posts
How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:14 AM|LINK
Hello
I have to Radio buttons
1. One way
2. Round trip
and there is two 2 text boxes for
1. Departing Date.
2. Return Date.
with asp:requiredFieldValidator.
The problem is that when user checked the "One way" the Return Date text box should be disabled. I disabled it but the Required field validator raises. And when i tried to disable the Required Field Validator an error occurred
"Microsoft JScript runtime error: Unable to set value of the property 'disabled': object is null or undefined"
Please Guide me how to solve this. I tried following :
<script type="text/javascript"> function disable_arrivals() { document.getElementById("<%=txtReturnDate.ClientID %>").disabled = true; document.getElementById("<%=RequiredFieldValidator2 %>").disabled = true; } </script> --------------------------------------------------------- <asp:TextBox CssClass="txtbox" ID="txtReturnDate" runat="server"></asp:TextBox> <ajax:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender3" runat="server" TargetControlID="txtReturnDate" WatermarkText="Click to select"></ajax:TextBoxWatermarkExtender> <ajax:CalendarExtender runat="server" TargetControlID="txtReturnDate" Format="dd,MMMM,yyyy"></ajax:CalendarExtender> <ajax:ValidatorCalloutExtender ID="ValidatorCalloutExtender3" runat="server" PopupPosition="TopRight" TargetControlID="RequiredFieldValidator3"></ajax:ValidatorCalloutExtender> <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" Display="none" SetFocusOnError="true" ControlToValidate="txtReturnDate" ErrorMessage="Please Select a Date."></asp:RequiredFieldValidator>Thank you
vijayano
Member
162 Points
51 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:20 AM|LINK
Hello,
Follow the links below. It will help you
http://manjuhpt.wordpress.com/2007/12/11/how-to-enabledisable-required-field-validator-in-javascript/
http://www.technoreader.com/Enable-Disable-RequiredFieldValidator-with-Javascript.aspx
vinay13mar
Star
7756 Points
1626 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:22 AM|LINK
Hi,
check the link
http://www.technoreader.com/Enable-Disable-RequiredFieldValidator-with-Javascript.aspx
http://www.eggheadcafe.com/community/asp-net/17/10303541/disabling-requiredfieldvalidator-in-javascript.aspx
http://stackoverflow.com/questions/2554840/dynamically-enable-or-disable-requiredfieldvalidator-based-on-value-of-dropdownl
V.K.Singh
sujithkumar
Contributor
3024 Points
563 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:25 AM|LINK
hi,
refer these
http://geekswithblogs.net/jonasb/archive/2006/08/11/87708.aspx
http://forums.asp.net/p/839953/840084.aspx
http://www.codeproject.com/Questions/126282/Dynamically-Enable-or-Disable-Required-Field-Valid
http://msdn.microsoft.com/en-us/library/Aa479045
kedarrkulkar...
All-Star
34295 Points
5514 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:28 AM|LINK
The best option in this scenario is to create a custom validator and in validation function, check if one way is checked then return date text could be blank else it should be entered etc....
if u only want to use requiredfieldvalidator, then try this code to disable the requiredfield validator.
<script type="text/javascript"> function disable_arrivals() { document.getElementById("<%=txtReturnDate.ClientID %>").disabled = true; ValidatorEnable(document.getElementById("<%=RequiredFieldValidator2 %>"), false); } </script>hope this helps...
KK
Please mark as Answer if post helps in resolving your issue
My Site
vsdev
Contributor
2230 Points
453 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:29 AM|LINK
You can do this
ValidatorEnable(document.getElementById('RequiredFieldValidator2'),false);Blog: dotnetthoughts
Download Capture It Plus
Taimoor Janj...
Member
164 Points
32 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:39 AM|LINK
Hi,
You can disable the validator this way,
<%=RequiredFieldValidator2.IsValid=true %>
Regards,
Muhammad Taimoor
dpkchhirang
Member
199 Points
164 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:40 AM|LINK
document.getElementById("<%=txtReturnDate.ClientID %>").disabled = true;
ValidatorEnable(document.getElementById('RequiredFieldValidator2'), false);
i tried this but same error occurred
Microsoft JScript runtime error: Unable to set value of the property 'enabled': object is null or undefined
dpkchhirang
Member
199 Points
164 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 04:43 AM|LINK
document.getElementById("<%=RequiredFieldValidator2.IsValid=true %>");
I tried above, error didn't come but Required Field Validator raises.
Please help
dpkchhirang
Member
199 Points
164 Posts
Re: How to Disable RequiredFieldValidator with javascript
Mar 05, 2012 05:07 AM|LINK
Thank you helping me
But still it's creating problem, I changed my code as following
function disable_arrivals(control, type) { if (type == "OneWay") { document.getElementById("<%=txtReturnDate.ClientID %>").disabled = true; ValidatorEnable(document.getElementById("<%=RequiredFieldValidator2 %>"), false); } } ---------------------------------------------------------------- <asp:RadioButton ID="rdoOneWay" runat="server" Text="One Way" GroupName="Trip" onclick="disable_arrivals(this,'OneWay');" />and get the error on following line(mark as bold)
function ValidatorEnable(val, enable) { val.enabled = (enable != false); ValidatorValidate(val); ValidatorUpdateIsValid(); }The error = "Microsoft JScript runtime error: Unable to set value of the property 'enabled': object is null or undefined"
thank you