1

I need to add the validation script for the DD entry.If DD number is already exists then it show alert at the time if submit. The page is PHP-MVC so my validation script needed to add in a JavaScript file.

Is it possible to validate inputs using MySql from JavaScript???

4
  • yes you retrieve the value from mysql to PHP variable and pass that variable into javascript alert. If you have done anything in coding, please do paste it too Commented Aug 10, 2015 at 5:22
  • I think you also need an ajax for this. api.jquery.com/jquery.ajax Commented Aug 10, 2015 at 5:31
  • here i need to call the php script from the JavaScript and then get the result from php script. How can i call&get result of php script from JS????? Commented Aug 10, 2015 at 5:33
  • Before calling your php script from submit use jquery ajax as mentioned by @VMcreator. This ajax will call your another php script/function which performs all your validations and return validation result/message. Use alert to display that result/message. Commented Aug 10, 2015 at 5:47

1 Answer 1

1

I am using one seperate php script to validate

<?php
          //db connectivity
          //Query
          //Value Checking

?>

then call this script from javascript using ajax

 <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script language="javascript">
   function getMeStatus(parameter){
    var def = $.Deferred();    // Create a deferred object
    $.ajax({                   // Make the ajax call
        type: "POST",
        url: "checkvalue.php",
        data: {check: parameter}
    }).done(function (data) {
       if (data !== "success"); {
          var val = confirm(data);
          if (val === false) {
             // Status was false?
             def.resolve(false);
          }
          else {
             // Status was true?
             def.resolve(true);
          }
       }
       else {
          // Status was true?
          def.resolve(true);
       }
    }
    // return a promise to supply the boolean status value later
    return def.promise();
 });
    </script>
Sign up to request clarification or add additional context in comments.

Comments

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.