Код: Выделить всё
Test
/////////////////////////////////////////////////////
function LessThanValidator(event)
{
var lowID = event.data.lowID;
var highID = event.data.highID;
var formID = event.data.formID;
var lowValue = parseInt( $(lowID).val() );
//var lowValue = parseInt( $(lowID).attr("value") ); // this doesn't fix
if ( isNaN(lowValue) ) {
lowValue = 0;
}
$(highID).rules('remove', 'min');
$(highID).rules('add', { min: lowValue });
$(formID).validate().element( highID );
return false;
}
function LargerThanValidator(event)
{
var lowID = event.data.lowID;
var highID = event.data.highID;
var formID = event.data.formID;
var highValue = parseInt( $(highID).val() );
//var highValue = parseInt( $(highID).attr("value") ); // this doesn't fix
if ( isNaN(highValue) ) {
highValue = 0;
}
$(lowID).rules('remove', 'max');
$(lowID).rules('add', { max: highValue });
$(formID).validate().element( lowID );
return false;
}
$(document).ready( function() {
// validate the #regFormBody form when it is submitted
$("#regFormBody").validate({
debug: true,
errorPlacement: function(error, element) {
error.insertAfter( element.parent() );
},
rules: {
confeelow: { required: true, digits: true, maxlength: 10, max: isNaN(parseInt($("#confeehigh"))) ? 0 : parseInt($("#confeehigh")) },
confeehigh: { required: true, digits: true, maxlength: 10, min: isNaN(parseInt($("#confeelow"))) ? 0 : parseInt($("#confeelow")) }
},
messages: {
confeelow: { max: "Please enter a value less than or equal to To (US$)" },
confeehigh: { min: "Please enter a value greater than or equal to From (US$)" }
}
});
///////////////////////////////////////////////////////////////
$("#confeelow").bind("change", {lowID: "#confeelow", highID: "#confeehigh", formID: "#regFormBody"}, LessThanValidator);
$("#confeehigh").bind("change", {lowID: "#confeelow", highID: "#confeehigh", formID: "#regFormBody"}, LargerThanValidator);
});
.error
{
color:red;
}
Desired Consulting Fee From (US$) *
To (US$) *
Для настройки проверки я использую следующий скрипт.
Код: Выделить всё
$("#confeelow").bind("change", { lowID: "#confeelow", highID: "#confeehigh", formID: "#profileFormBody" }, LessThanValidator);
$("#confeehigh").bind("change", { lowID: "#confeelow", highID: "#confeehigh", formID: "#profileFormBody" }, LargerThanValidator);
Вот HTML-скрипт, который вызывает проблемы:
Код: Выделить всё
Без предопределенного значения у меня нет проблем:
Код: Выделить всё
Спасибо
р>
Код: Выделить всё
///////////////// Update-001 ////////////////////
Код: Выделить всё
1> First the user will be allowed to enter data
2> Second the user will submit the form and store in DB
3> When next time the user logins again
I have to repopulate the text field by using some code similar as follows:
Подробнее здесь: [url]https://stackoverflow.com/questions/3606118/jquery-why-the-validation-rule-doesnt-support-predefined-value[/url]