starphp Posted April 6, 2009 Share Posted April 6, 2009 Hello, I want to validate a field by using JQuery and it also need to consider the value of another field during the checking. I have the following: <script type="text/javascript"> $().ready(function() { $.validator.addMethod("textOnly", function(value, element) { var embarkation_region_id = document.getElementById('embarkation_region_id').value; var embarkation_port = document.getElementById('embarkation_port').value; $.ajax({ type: "POST", url: "validate_embarkation_port.php", data: "embarkation_region_id=" + embarkation_region_id + "&embarkation_port=" + embarkation_port, dataType: "text", success: function(msg) { if(msg == 'sucess') return true; else return false; } }); }, "This Region-Port combination exists." ); // validate form on keyup and submit $("#editembport").validate({ rules: { embarkation_port: { required: true, textOnly: true } }, messages: { embarkation_port: { required: "Please enter Embarkation Port" } } }); }); </script> Form fields are: Region: <input type="text" name="embarkation_region_id" id="embarkation_region_id" class="required" /> Port: <input type="text" name="embarkation_port" id="embarkation_port" class="required embarkation_port textOnly" /> When someone press the submit button, i want to validate the "Port" value by using Ajax.. And also need to pass the value of "Region". Note: The ajax page (validate_embarkation_port.php) returns the text value "success" or "error". And whatever value it returns, the JQuery shows the error message. Please help me to fix this problem. Thank You Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.