A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearUse Ajax to call PHP function for HTML button Onclick - page 1
User InfoPosts
Use Ajax to call PHP function for HTML button Onclick#1
I have a an HTML button where I want the onclick to call a PHP function. I need to use AJAX to do this but I am totally lost. There is more that occurs inside the php function, but I didn(t see the need of including it. Below is code thus far:

<HTML>
<BODY>
<FORM>
<input text="text" name=airport1 id=airport1 />
<input text="text" name=airport2 id=airport2 />
<input type="button" value="Enter" onclick=PrintDist()/>
</FORM>
</BODY>
</HTML>

<?php

function PrintDist(){
$icao1 = $_REQUEST["airport1"];
$icao2 = $_REQUEST["airport2"];
}
?>

posted date: 2009-04-15 18:53:00


Re: Use Ajax to call PHP function for HTML button Onclick#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-15 18:53:01


Re: Use Ajax to call PHP function for HTML button Onclick#3
Using jQuery (untested):function PrintDist() { var submitButton = $(this).find((*:submit(); $.post(this.action, $(this).serialize(), function() { alert((Form submitted!(); submitButton.attr((disabled(, (false().attr((value(, (Enter(); }); submitButton.attr((disabled(, (true().attr((value(, (Posting...(); return false;}Use a proper form as your HTML (for people without Javascript, and for the script to work nicely):<form action="xxx" method="post" onsubmit="return PrintDist()"> <input text="text" name="airport1" id="airport1" /> <input text="text" name="airport2" id="airport2" /> <input type="submit" value="Enter" /></form>

posted date: 2009-04-15 19:18:00


Re: Use Ajax to call PHP function for HTML button Onclick#4
Use any javascript library to make ajax calls to the php script on the server. For example:jqueryprototypeOr if you just want really simple stuff, take a look at the sajax ajax toolkit for php

posted date: 2009-04-15 19:28:00


Re: Use Ajax to call PHP function for HTML button Onclick#5
thanks for nice and simple example, form onsubmit is THE KEY

posted date: 2011-10-03 05:14:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.