I am trying to find a away (the correct and easy way) to use IF and else IF statements in javascript.
here is what I am trying to do...
at the moment, I am joining 2 input fields value and display them in another input balue like so:
function FillIn() {
document.getElementById('custom').value =
'Main Text:' + ' ' + document.getElementById('inputName').value + ', ' + '1st Text:' + ' ' + document.getElementById('inputName101').value
;
}
so basically the above code will place the values of inputName and inputName101 into the custom input field. this works just fine.
Now, I have 2 radio buttons which I want to display their Values into the custom input field depending on which one is selected/checked.
for this I am using the following code:
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 not sure if I am doing this correctly as I don't get the values of radio buttons in the custom input field at all..
Could someone please advise on this?
EDIT:
HTML for 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);">