I am looking to implement a simple validation check on my HTML form. Specifically, I want an error message to appear next to the dropdown select if the user chooses the "18 - 24" option, stating 'You must be 25+'.
<select class="element select medium" id="element_3" name="element_3">
<option value="" selected="selected"></option>
<option value="1" class="error" id="error">18 - 24</option>
<option value="2" >25 - 34</option>
<option value="3" >35 - 44</option>
<option value="4" >45 +</option>
Initially, I tried adding both a class and ID to value 1. Then, I attempted using the following JavaScript code:
function hidestuff(page){
document.getElementById(error).style.visibility="hidden";
}
function showstuff(error){
document.getElementById(error).style.visibility="visible";
}
I tried toggling between showing and hiding the error message using JavaScript. My goal was to hide the message when the page loads, and then display it when the error div is toggled. However, this approach did not work as intended. I also included the corresponding CSS. Could someone provide guidance on how to properly implement this functionality?