How do you call a PHP function from an onchange equals in an HTML form?
-
-
Answer:
You would have to do this using an AJAX request. The onchange event would trigger a Javascript function that would in turn send a request to the server, and handle the response. This requires a fair bit of back-end code for handling the AJAX, and I would recommend using an existing library for that purpose. jQuery is the one that I am familiar with, and you could handle that change event like so: <?php if(array_key_exists('mytext', $_POST)){ echo "The text you posted is "{$_POST['mytext']}""; exit; } ?> <script src="(jquery source URL here)" type="text/javascript"></script> <!-- ... --> <input type="text" id="mytext"></input> <div id="result"></div> <script type="text/javascript"> $("#mytext").change(function(){ $.post("myscript.php", {'mytext':$("#mytext").val()}, function(dat){ $("#result").HTML(dat); }); }); </script>
wiki.answers.com Visit the source
Related Q & A:
- How to speed up a wordpress function with multiple loops?Best solution by WordPress
- How to dynamically create a PHP class name on the fly?Best solution by stackoverflow.com
- how to call a function in Python in another function?Best solution by Yahoo! Answers
- How to start creating a php script, that will be installed on many servers?Best solution by Stack Overflow
- How do I call a cell phone in Australia?Best solution by wiki.answers.com
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.