I have two textboxes if i insert a value in Landscaping, then Compound Walling gets disabled
Enter Value for Landscaping
Html.TextBoxFor(model => model.landscapingsqm, htmlAttributes: new { id = "landscape", class = "form-control", onchange = "onchangeland()" })
Html.ValidationMessageFor(model => model.landscapingsqm, "", new { class = "text-danger" })
Html.TextBoxFor(model => model.landscapingsqm, htmlAttributes: new { id = "landscape", class = "form-control", onchange = "onchangeland()" })
Html.ValidationMessageFor(model => model.landscapingsqm, "", new { class = "text-danger" })
Enter Value for Compound Walling
Html.TextBoxFor(model => model.compoundwalling, htmlAttributes: new { id = "compoundwall", class = "form-control", onchange = "onchangecompoundwalling()" })
Html.ValidationMessageFor(model => model.compoundwalling, "", new { class = "text-danger" })
Html.TextBoxFor(model => model.compoundwalling, htmlAttributes: new { id = "compoundwall", class = "form-control", onchange = "onchangecompoundwalling()" })
Html.ValidationMessageFor(model => model.compoundwalling, "", new { class = "text-danger" })

Vishal JoshiRank #377 · 6.7K reputationPosted May 29, 2024, 5:59 AM EDT
Hello,
You can check on the page load/Edit the record. try the below sample code to fix the change.
$( document ).ready(function() { function ajaxCalltoGetData(data){ if(data && data.compoundwall.value > 0){ $("#compoundwall").prop("readonly", true); } else{ $("#compoundwall").prop("readonly", false); } } });Thanks
Vishal Joshi
Amit MohantyRank #112 · 20K reputationPosted May 28, 2024, 7:40 AM EDT
Try this:
Enter Value for Landscaping @Html.TextBoxFor(model => model.landscapingsqm, new { id = "landscape", class = "form-control", onchange = "onchangelandscaping()" }) @Html.ValidationMessageFor(model => model.landscapingsqm, "", new { @class = "text-danger" }) function onchangelandscaping() { var landscapeValue = document.getElementById("landscape").value; var compoundWallInput = document.getElementById("compoundwall"); if (landscapeValue) { compoundWallInput.disabled = true; } else { compoundWallInput.disabled = false; } }Vikas SinghRank #441 · 5.7K reputationPosted May 28, 2024, 7:58 AM EDT
@Garima, you can try below one-
Enter Value for Landscaping
@Html.TextBoxFor(model => model.landscapingsqm, new { id = "landscape", class = "form-control", onchange = "onchangeland()" })
@Html.ValidationMessageFor(model => model.landscapingsqm, "", new { class = "text-danger" })
Enter Value for Compound Walling
@Html.TextBoxFor(model => model.compoundwalling, new { id = "compoundwall", class = "form-control", onchange = "onchangecompoundwalling()" })
@Html.ValidationMessageFor(model => model.compoundwalling, "", new { class = "text-danger" })
Tuhin PaulRank #7 · 71.9K reputationPosted May 31, 2024, 2:28 PM EDT
Sample Page $(document).ready(function() { // Mock data fetching function function fetchData() { // Simulating an AJAX call to get data return new Promise((resolve) => { setTimeout(() => { resolve({ compoundwall: { value: 1 } }); }, 1000); }); } function ajaxCalltoGetData(data) { if (data && data.compoundwall.value > 0) { $("#compoundwall").prop("readonly", true); } else { $("#compoundwall").prop("readonly", false); } } // Fetch data on page load and update input field based on the data fetchData().then((data) => { ajaxCalltoGetData(data); }); });A mock fetchData function is added to simulate an AJAX call. The ajaxCalltoGetData function is called with the fetched data once the document is ready.