I have few fields which need to be disabled based on a value which is being defined in the js file. Is it possible to do so?
I have few fields which need to be disabled based on a value which is being defined in the js file. Is it possible to do so?
Instead of setting disabled through javascript you could add the disabled to the HTML input element:
<input class="form-control" id="form_input" disabled="disabled" .... />
Then in your javascript:
document.getElementById('form_input').onchange = function ()
{
if (this.value == '0')
{
document.getElementById("form_input").disabled = true;
}
else
{
document.getElementById("form_input").disabled = false;
}
}
not sure if it just in JS possible, but with react:
function() {
const [value, setValue] = useState(false)
const handleChange= () => {
setValue(!value)
}
return(
<>
<input type="checkbox" onClick={handleChange}/>
<input type="text" disabled={value}/>
</>
)}
then you validate the value with a function in your script.