I am struggling to figure out the correct and efficient way to implement IF and else IF statements in javascript.
Here is my current challenge...
Currently, I am combining the values of 2 input fields and displaying them in another input field like this:
function FillIn() {
document.getElementById('custom').value =
'Main Text:' + ' ' + document.getElementById('inputName').value + ', ' + '1st Text:' + ' ' + document.getElementById('inputName101').value
;
}
The code mentioned above successfully puts the values of inputName
and inputName101
into the custom
input field.
Now, I have two radio buttons that I want to display their values in the custom input field based on the selected one.
Here is the code I am using for this purpose:
function FillIn() {
document.getElementById('custom').value =
'Main Text:' + ' ' + document.getElementById('inputName').value + ', ' + '1st Text:' + ' ' + document.getElementById('inputName101').value
if(document.getElementById('male').checked) {
+ ', ' + 'Type:' + ' ' + document.getElementById('male').value
}else if(document.getElementById('female').checked) {
+ ', ' + 'Type:' + ' ' + document.getElementById('female').value
}
;
}
However, I am facing an issue as the radio button values are not showing up in the custom
input field at all.
Any guidance or advice on how to resolve this would be greatly appreciated.
EDIT:
Below is the HTML for the radio buttons:
<input id="male" type="radio" name="gender" value="Road Legal" onclick="showhidediv(this);">
<input id="female" type="radio" checked="checked" name="gender" value="Show Plate" onclick="showhidediv(this);">