+ 1
How to show a message in javascript?
How to show an error if there is no change in option? If no valid option is selected. CODE:- <select name="gender"> <option disabled="disabled" selected="selected">Gender</option> <option>Male</option> <option>Female</option> <option>Other</option> </select>
5 odpowiedzi
+ 3
You have to use onchange event of select element and a JavaScript function to check which value is selected.
Here is basic code for it.
HTML:
<form name="myForm" onchange="displayValue()">
<select name="gender">
<option>Male</option>
<option>Female</option>
</select>
</form>
JavaScript:
function displayValue() {
console.log(document.myForm.gender.value);
}
+ 1
Farino i implement your code but problem not fixed yet I'm providing you my code under form tag
https://code.sololearn.com/wO5pRk269vie/?ref=app
0
i want to display the message "No valid option is selected" if default "Gender" option is selected when i click on Submit..
0
Faisal Rahman I gave you basic code and idea of doing it, try to implement yourself for better practice and let us know if you have any problem trying to implement it 🤓
0
🔫 Rick Grimes Your code will respond on change but i want to respond it even if there is no change in option