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
Related Q & A:
- How to style the HTML5 form validation messages?Best solution by Stack Overflow
- How does the form validation work on angularjs with ionic?Best solution by blog.nraboy.com
- How to upload file using ajax php?Best solution by Stack Overflow
- What to do with the error message "Internet explorer has encountered a problem and needs to close?Best solution by Yahoo! Answers
- What is an easy code for a form in PHP?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.