I'm trying to add some JavaScript into my HTML for the first time.
Have made it this far from helpful replies on this forum; I have something that I think is close, but doesn't work:
HTML
<select id="carSelect">
<option></option>
<option value="Audi">Audi</option>
<option value="Ferrari">Ferrari</option>
<option value="Fiat">Fiat</option>
</select>
<p id="choiceDisplay">
Selection Display
</p>
JavaScript:
$('select').change(function(){
const options = $("option");
let selectedOption = "";
let displayString = "";
options.each(function(index){
let option = options[index];
if($(option).prop("selected")) {
selectedOption = $(option).val();
};
if(selecetedOption === "Audi") {
displayString = "Oh I used to have one of those";
};
});
$("#choiceDisplay").empty().append(displayString);
});
I have a jsfiddle link too.