0

I want to run a php script each time the input value of the <input type="text">changes, for like checking if the passwords in a registration form are the same

5
  • 2
    Have you ever heard of AJAX call? Commented Jul 3, 2013 at 6:04
  • Then search for it. Your problem is not that hard. Commented Jul 3, 2013 at 6:09
  • This is a job better suited for javascript. Commented Jul 3, 2013 at 6:09
  • Yes, but for the username, you need check with the database Commented Jul 3, 2013 at 6:12
  • true... so ajax would be the best approach. Commented Jul 3, 2013 at 6:13

4 Answers 4

2

PHP is server side scripting language, so when you submit the form then it will check the value of both textboxes..

Instead of PHP you can use JavaScript or jQuery or AJAX to check the value of both text box.

Sign up to request clarification or add additional context in comments.

6 Comments

I know how to do this in JavaScript, but can I run a php script via JavaScript code?
ajax in this case is dumb... learning how to do field comparisons is going to be easier then learning to do a ajax call for a js newbie
@Orangepill you are right, jQuery and JS is good for this type of solutions, AJAX comes when need to check email and username is already in database or not
I also need the username check, so AJAX it'll be?
@NickPeelman I would suggest using a ajax library like jquery for that, it will help you avoid a whole lot of cross-browser implementation BS that you will have to otherwise.
|
0

PHP is a server side language, and its work is finish once the processing completes and the HTML is thrown out to the browser. It can only only responds to user actions if a new server side request is generated for every user inout.

Where as javascript is the client side language, which can interact with the user and server both.

Now if you want to hit on the server, on every user input in the text box, then you have to do it using javascript, which indirectly send a ajax call to the server to get its response, and to do the required changes.

Comments

0

Another good option (especially if you do your processing on the same page) would be to simply check the field when the user submits it.

If it meets the required standards let it pass, otherwise just repopulate the fields with the data that was submitted, and produce some error text next to the field(s) that need it.

Its not as "pretty" as an AJAX solution, but its almost as convenient and is very easy to do in PHP.

Comments

0
<form  method="POST" onsubmit="return check()"> 
 <input type="password" name="pass" id="pass" onchange="check(this)>
 <input type="password" name="pass1" id="pass1" onchange="check(this)>
</form>

and than javascript

 function check()
 {
  var pass = document.getElementById('pass').value;
  var pass1 = document.getElementById('pass1').value;

   if(pass1 != pass)
   {
     alert("Pass don't macth");
     return false;
   }
 }

maybe something like that?

1 Comment

This does work, but I had to call a php script so I could access usernames on my MySQL server to check if the username exists or not :)

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.