1

How to show error message if dropdown option not picked. when click next and message should appear please see the below picture.enter image description here

1 Answer 1

0

If you are doing it on frontend then why you didn't validate the form before submit here is an example

<select id="select-gender" form="myForm" name="radios">
  <option id="opt-default" form="myForm" value="" selected> Please Select </option>
  <option id="sexmale" name="radios" value="Male" form="myForm"> Male </option>
  <option id="sexfemale" name="radios" value="Female" form="myForm"> Female </option>
</select>


<button onclick="validateForm()">Submit</button>
<form name="myForm" id="myForm" onsubmit="return validateForm()" method="post">
</form>

Javascript Code

//Error Msg for input field
function validateForm() {

  let gender = document.forms["myForm"]["radios"].value;

  if (gender == "") {

    //You can use soft messenging using Jquery as well
    alert("Please select your Gender");
    return false;

  }
}
2
  • How to get the ID of the button because it a theme button secondly it not radio buttons @Syed
    – Bayzel
    Aug 30, 2022 at 13:25
  • For instance cannot you get it by inspect ? Aug 31, 2022 at 3:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.