How to do searching in PHP and AJAX?

Problem to add separate error divs for each form with AJAX/PHP Validation?

  • Now i have next files: Index.php ( Where are the 2 form) login.php (login PHP validation) submit.php (register validation) script.js (the problem is here think) My main question how is how i diference in this javascript code the error box. I have 2 error boxes: For login -> #error-login For register -> #error In index.php i have managed to put the forms and they are working correctly, without errors. The unique problem there is that by pressing submit it post me all in #error box and i dont know how to manage in best way to get it separe. heres the code: $(document).ready(function(){ $('#regForm').submit(function(e) { register(); e.preventDefault(); }); $('#loginForm').submit(function(e) { login(); e.preventDefault(); }); }); function register() { hideshow('loading',1); error(0); $.ajax({ type: "POST", url: "submit.php", data: $('#regForm').serialize(), dataType: "json", success: function(msg){ if(parseInt(msg.status)==1) { window.location=msg.txt; } else if(parseInt(msg.status)==0) { error(1,msg.txt); } hideshow('loading',0); } }); } function login() { hideshow('loading2',2); error(0); $.ajax({ type: "POST", url: "login.php", data: $('#loginForm').serialize(), dataType: "json", success: function(msg){ if(parseInt(msg.status)==2) { window.location=msg.txt; } else if(parseInt(msg.status)==0) { error(2,msg.txt); } hideshow('loading',0); } }); } function hideshow(el,act) { if(act) $('#'+el).css('visibility','visible'); else $('#'+el).css('visibility','hidden'); } function error(act,txt) { hideshow('error',act); if(txt) $('#error').html(txt); }

  • Answer:

    perhaps you should differentiate which form is submitted by detecting which submit button was clicked.. for example: $(document).ready(function(){ $('#registerSubmit').click(function(){ $('#regForm').submit(function(e) { register(); e.preventDefault(); }); }); $('#loginSubmit').click(function(){ $('#loginForm').submit(function(e) { login(); e.preventDefault(); }); }); }); ...

Igor at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.