i am trying to make,when checkbox is checked textbox should be shown but when check box is unchecked text box should be hide.This is how i implement this so far.
Examination Required:
Remarks Examination:

Sachin SinghRank #66 · 26.2K reputationPosted Sep 21, 2022, 2:04 AM EDT
$(function() { if($("[id*='chkexamination']").is(":checked")) {$("[id*='chkremarks']").show(); } ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']").is(":checked")); })$("[id*='chkexamination']").click(function () { if ($(this).is(":checked")) { $("[id*='chkremarks']").show(); ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']").is(":checked")); } else { $("[id*='chkremarks']").hide(); ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']").is(":checked")); } } );Yes, there was a typo
Vishal YelveRank #178 · 13.6K reputationPosted Sep 20, 2022, 1:41 AM EDT
Try this
$(function () { $("#chkexamination").click(function () { if ($(this).is(":checked")) { $("#chkremarks").show(); } else { $("#chkremarks").hide(); } }); });Garima BansalRank #1,554 · 1K reputationPosted Sep 20, 2022, 1:44 AM EDT
the way i am using its working but i want it when page open
Sachin SinghRank #66 · 26.2K reputationPosted Sep 20, 2022, 1:55 AM EDT
Use below code
1. For page load
2.For checkbox check
add below lines of code
$(function() { if( $([id*='chkexamination']).is(":checked")){$("[id*='chkremarks']").show(); } }) $("[id*='chkexamination']").click(function () {if ($(this).is(":checked")) { $("[id*='chkremarks']").show();} else {$("[id*='chkremarks']").hide(); } } );Sachin SinghRank #66 · 26.2K reputationPosted Sep 20, 2022, 1:57 AM EDT
@Garima your answer is wrong , if in the first load your checkbox will be checked (suppose for edit) then also div will not display, until you uncheck the checkbox.
Garima BansalRank #1,554 · 1K reputationPosted Sep 20, 2022, 6:42 AM EDT
Sachin Singh
there is a problem, when i dont need any data insert in textbox then its data is not saving
Garima BansalRank #1,554 · 1K reputationPosted Sep 20, 2022, 6:48 AM EDT
as i use required field validator, senerio is when textbox hidden then requiredfield validator is enale
Sachin SinghRank #66 · 26.2K reputationPosted Sep 20, 2022, 7:30 AM EDT
@Garima, you need to do this to disable the validator
$(function() {if($([id*='chkexamination']).is(":checked")){$("[id*='chkremarks']").show();ValidatorEnable($("[id*=chkremarks]"), $("[id*=chkexamination]").is(":checked"));} }) $("[id*='chkexamination']").click(function () { if ($(this).is(":checked")) { $("[id*='chkremarks']").show(); } else { $("[id*='chkremarks']").hide(); } ValidatorEnable($("[id*=chkremarks]"), $("[id*=chkexamination]").is(":checked")); } );Garima BansalRank #1,554 · 1K reputationPosted Sep 20, 2022, 7:44 AM EDT
can i remove required field validtor ?
Garima BansalRank #1,554 · 1K reputationPosted Sep 20, 2022, 7:51 AM EDT
Whether Further Examination Required:
$(function () {
if ($([id *= 'chkexamination']).is(":checked")) {
$("[id*='chkremarks']").show();
ValidatorEnable($("[id*=chkremarks]"),
$("[id*=chkexamination]").is(":checked"));
}
})
$("[id*='chkexamination']").click(function () {
if ($(this).is(":checked")) {
$("[id*='chkremarks']").show();
}
else {
$("[id*='chkremarks']").hide();
}
ValidatorEnable($("[id*=chkremarks]"), $("[id*=chkexamination]").is(":checked"));
}
);
i use this , but not working
Sachin SinghRank #66 · 26.2K reputationPosted Sep 20, 2022, 8:04 AM EDT
If you will remove then it will not be a required field even when checkbox is checked. However save will start working.
Sachin SinghRank #66 · 26.2K reputationPosted Sep 20, 2022, 8:06 AM EDT
Give it a try
$(function() { if($([id*='chkexamination'])[0].is(":checked")){$("[id*='chkremarks']")[0].show(); ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']")[0].is(":checked"));} }) $("[id*='chkexamination']").click(function () { if ($(this).is(":checked")) {$("[id*='chkremarks']")[0].show(); } else {$("[id*='chkremarks']")[0].hide(); } ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']")[0].is(":checked")); } );Garima BansalRank #1,554 · 1K reputationPosted Sep 21, 2022, 12:43 AM EDT
Sachin Singh
by applying your updated code, now hidden textbox is not visible
Sachin SinghRank #66 · 26.2K reputationPosted Sep 21, 2022, 1:43 AM EDT
@Garima, Test this
$(function() { if($([id*='chkexamination']).is(":checked")) { $("[id*='chkremarks']").show(); } ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']")[0].is(":checked")); }) $("[id*='chkexamination']").click(function () { if ($(this).is(":checked")) { $("[id*='chkremarks']").show(); ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']")[0].is(":checked")); } else { $("[id*='chkremarks']").hide(); ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']")[0].is(":checked")); } } );Garima BansalRank #1,554 · 1K reputationPosted Sep 21, 2022, 1:50 AM EDT
getting an error in while i see in console
$(...)[0].is is not a function
Sachin SinghRank #66 · 26.2K reputationPosted Sep 21, 2022, 1:52 AM EDT
There is no [0].is in my updated code, you copied from my earlier replies, please check the latest one. Copy from sept 21st reply
Garima BansalRank #1,554 · 1K reputationPosted Sep 21, 2022, 1:58 AM EDT
now, error is
id is not defined
Garima BansalRank #1,554 · 1K reputationPosted Sep 21, 2022, 2:47 AM EDT
i tryed and tested each one of your solution but i dont find where is the problem
Garima BansalRank #1,554 · 1K reputationPosted Sep 21, 2022, 2:57 AM EDT
i have one checkbox i.e. if checkbox is checked then textbox show oherwise hiddden
and on button Save if checkbox is unchecked then required field validator must be disable
Whether Further Examination Required:
Garima BansalRank #1,554 · 1K reputationPosted Sep 21, 2022, 3:41 AM EDT
there is big mistake, ID of requiredfield is in correct
$(function () {
if ($("[id*='chkexamination']").is(":checked")) {
$("[id*='chkremarks']").show();
}
ValidatorEnable($("[id*='RequiredFieldValidator4']")[0], $("[id*='chkexamination']").is(":checked")); //correct ID
ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']").is(":checked")); //incorrect ID
})
$("[id*='chkexamination']").click(function () {
if ($(this).is(":checked")) {
$("[id*='chkremarks']").show();
ValidatorEnable($("[id*='RequiredFieldValidator4']")[0], $("[id*='chkexamination']").is(":checked")); //correct ID
ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']").is(":checked")); //incorrect ID
}
else {
$("[id*='chkremarks']").hide();
ValidatorEnable($("[id*='RequiredFieldValidator4']")[0], $("[id*='chkexamination']").is(":checked")); //correct ID
ValidatorEnable($("[id*='chkremarks']")[0], $("[id*='chkexamination']").is(":checked")); //incorrect ID
}
}
);
Garima BansalRank #1,554 · 1K reputationPosted Sep 20, 2022, 1:52 AM EDT
its done,
i use the property