Im trying to trigger a function every time a different radio button is clicked in my form. This is the form:
<FormControl>
<RadioGroup
row
aria-labelledby="demo-row-radio-buttons-group-label"
name="row-radio-buttons-group"
value = {selectionValue}
onChange={handleSelection}
>
<FormLabel id="demo-radio-buttons-group-label">Price Selection</FormLabel>
<FormControlLabel id="standard" value="standard" control={<Radio />} label="standard" />
<FormControlLabel id="premium" value="premium" control={<Radio />} label="premium" />
<FormControlLabel id="excelium" value="excelium" control={<Radio />} label="excelium" />
</RadioGroup>
</FormControl>
and it triggers this onChange={handlefunction} which works and calls serviceCalc():
const [selectionValue, setSelectionValue] = useState("")
const handleSelection = (event : any) => {
setSelectionValue(event.target.value);
serviceCalc()
}
my problem is when I get to serviceCalc() the function prints my console.log and thats it. how can I get standard(), premium() and excelium() to go trough?
const serviceCalc = () => {
console.log("service calc")
const standard1 = (document.getElementById("standard") as HTMLInputElement);
const premium1 = (document.getElementById("premium") as HTMLInputElement);
const excelium1 = (document.getElementById("excelium") as HTMLInputElement);
if (standard1.checked){
standard();
}
else if (premium1.checked) {
premium();
}
else if (excelium1.checked) {
excelium();
}
}
any help is greatly appreciated.
checkeddoes not exist on the objects or it is falsestandard1orstandard1.checkedto see