Reputation: 179
I am facing a strange programming problem.
I've a page for user registration. I am using JavaScript code to disable text boxes when user selects no from option.
But after the selecting Option 'No' from drop down list, page is not getting submitted and not redirecting to next page.
And surprisingly, if I select every 'Yes' & fill text box, then it submits smoothly and redirect to next page.
I suspect this is JavaScript problem. Need help please !
Here is my javasctipt code sample
function DisableEnable2() {
var ddlCnovict = document.getElementById("<%= ddlConviction.ClientID %>")
var txtConDate = document.getElementById("<%= txtConvictDate.ClientID %>")
var txtConDetail = document.getElementById("<%= txtConvictionDetails.ClientID %>")
if (ddlCnovict.options[ddlCnovict.selectedIndex].text == "No") {
txtConDate.disabled = true;
txtConDetail.disabled = true;
}
else {
txtConDate.disabled = false;
txtConDetail.disabled = false;
}
}
Asp code:
Yes No
Upvotes: 0
Views: 99
Reputation: 2344
disable your validators when you don't need textboxed to be required:
function DisableEnable2() {
var ddlCnovict = document.getElementById("<%= ddlConviction.ClientID %>")
var txtConDate = document.getElementById("<%= txtConvictDate.ClientID %>")
var txtConDetail = document.getElementById("<%= txtConvictionDetails.ClientID %>")
var txtConDateValidatior = document.getElementById("<%= txtConvictDateValidatior.ClientID %>")
var txtConDetailValidatior = document.getElementById("<%= txtConvictionDetailsValidatior.ClientID %>")
if (ddlCnovict.options[ddlCnovict.selectedIndex].text == "No") {
ValidatorEnable(txtConDateValidatior, false);
ValidatorEnable(txtConDetailValidatior, false);
txtConDate.disabled = true;
txtConDetail.disabled = true;
}
else {
ValidatorEnable(txtConDateValidatior, true);
ValidatorEnable(txtConDetailValidatior, true);
txtConDate.disabled = false;
txtConDetail.disabled = false;
}
}
I know there are validations by the author's comment response:
@kobe, yes. I've validators. – user2285026 10 mins ago
Upvotes: 2
Reputation: 39
Instead of disabling the control use the attribute function to add the disable attribute:
txtConDate.Attributes.Add("disabled","true");
and on selecting "YES" do this,
txtConDate.Attributes.Clear("disabled");
Upvotes: 0
Reputation: 735
So, I have never seen such constructions in HTML
<%= ddlConviction.ClientID %>
It's looks like scriplets on server side and on the client it should be transformed into something different.
I think you have a JS error on the page, because JS can't find
<%= ddlConviction.ClientID %>
and your
txtConDetail
for example is NULL, so the construction
txtConDetail.disabled
will cause the error.
Try to use DevTools in Chrome or FireBug in FireFox, also see the page source in browser.
Upvotes: 0