2

This my attempt at validating a dropdown list. Its actually a flip switch in jquery mobile. I want to force the user to answer "yes" in order to pass validation. I'm trying to figure out a way to do this using the jquery validation plugin. This works fine for text and list boxes however, I cannot seem to get validation to work with a drop down list. I have also created a fiddle here. Any help here is greatly appreciated. Thank you.

<script src="http://jquery.bassistance.de/validate/jquery.validate.js"></script>
<script src="http://jquery.bassistance.de/validate/additional-methods.js"></script>
<body>
<form id="frmTest">
    <label for="txtName">Name:</label>
    <input type="text" id="txtName" name="txtName" placeholder="Enter your name">
    <label for="lstAnswer">Did you enter your name?</label>
    <select id="lstAnswer" name="lstAnswer" data-role="slider">
        <option value="0">No</option>
        <option value="1">Yes</option>
    </select>
    <br /><br />
    <input type="submit" id="butSubmit" value="Check Test" />
</form>
</body>


jQuery.validator.setDefaults({
debug: true,
success: "valid"
});
$("#frmTest").validate({
messages: {
    txtName: {
        required: "Please enter your name",
    },
    lstAnswer: {
        required: "Please select Yes",
    }        
},
rules: {
    txtName: {
        required: true
    },
    lstAnswer: {
        required: true
    }
}
});
3
  • Try this answer stackoverflow.com/questions/14896854/… Commented Aug 26, 2013 at 23:08
  • The problem seems to be when jquery mobile is introduced into this scenario Commented Aug 27, 2013 at 17:19
  • working with slider is hectic. I try always to avoid them :/ if its going to drive you crazy, replace it with a checkbox, it looks nice :) Commented Aug 27, 2013 at 17:21

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.