Magento 1.9 – Validation for Dropdown

magento-1.9validation

My code:

<select class="validate-select" title="subjects" id="subjects1" name="subject" >
    <option value=""><?php echo $this->__("Please select Subject");?></option>
    <option value="english"><?php echo $this->__("English");?></option>
    <option value="maths"><?php echo $this->__("Maths");?></option>
    <option value="science"><?php echo $this->__("Science");?></option>

</select>
<select class="validate-select" title="subjects" id="subjects" name="subjects" >
    <option value=""><?php echo $this->__("--Please select Subject--");?></option>
    <option value="general paper"><?php echo $this->__("General Paper");?></option>
    <option value="biology"><?php echo $this->__("Biology");?></option>
    <option value="chemistry"><?php echo $this->__("Chemistry");?></option>
    <option value="physics"><?php echo $this->__("Physics");?></option>

</select>

Don't know why but i m not getting error message

enter image description here

like this message should be display please select option but i m not getting it how to display message

Best Answer

enter image description here after seeing your code i realize that you are repeating the id element you have same id for both the id must be unique so change one element id to id="subjects1".
hope this will helps. i tested myself and it working..

<form id="request_tutor">
<select class="validate-select" title="subjects" id="subjects1" name="subject" >
    <option value=""><?php echo $this->__("Please select Subject");?></option>
    <option value="english"><?php echo $this->__("English");?></option>
    <option value="maths"><?php echo $this->__("Maths");?></option>
    <option value="science"><?php echo $this->__("Science");?></option>

</select>
<select class="validate-select" title="subjects" id="subjects" name="subjects" >
    <option value=""><?php echo $this->__("--Please select Subject--");?></option>
    <option value="general paper"><?php echo $this->__("General Paper");?></option>
    <option value="biology"><?php echo $this->__("Biology");?></option>
    <option value="chemistry"><?php echo $this->__("Chemistry");?></option>
    <option value="physics"><?php echo $this->__("Physics");?></option>

</select>
<input type="submit" value="submit">
</form>
<script type="text/javascript">
    //< ![CDATA[
        var customForm = new VarienForm('request_tutor', true);
        //]]>
        </script>
Related Topic