The JQuery validator plugin uses the “name” and I would like to find it dynamically by ID. My $test variable returns a string with the correct name but then I can’t use a string.
How can I use this variable to replace the hard coded name (ctl00$MainContent$ListBox1)?
Instead of:
<script type="text/javascript">
$(document).ready(function () {
var $test = $("#ListBox1").attr("name");
$("#form1").validate({
rules: {
ctl00$MainContent$ListBox1: {
required: true,
rangelength: [0, 4]
}
},
messages: {
ctl00$MainContent$ListBox1: {
required: "Please select a state",
rangelength: "Please select maximum 4 states"
}
},
errorLabelContainer: $("#message")
});
});
</script>
I would like to use something like:
$("#form1").validate({
rules: {
$test: {
required: true,
rangelength: [0, 4]
}
},
You can’t actually replace a member id. You can however augment objects:
Now your
messagesandrulesobject both contain a member with your saved name.