That's not actually running the PHP function onchange. It's running a Javascript function onchange. The PHP function only runs once when the page is loaded.
ShawnCplus
Code Monkey
1,583 posts since Apr 2005
Reputation Points: 526
Solved Threads: 268
And also to test your theory below is some code the will prove that javascript cannot communicate with php:
<?
function myfunction($var){
return $var;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script language="javascript" type="text/javascript">
function ILovePHP(var1) {
b = "<?=myfunction('var1');?>";
alert(b);
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<form action="" method="post"><input name="armandecastro" name="armandecastro" type="text" onChange="ILovePHP('this is a test string');"></form><p>
</body>
</html>
Now in the above example, the alert box should contain the text 'this is a test string' but instead it just has var1 because it cannot pass variable 1 to php. So try entering the text in the javascript function and getting php to process it and you will get the above results.
Edit:
By saying that, there is nothing stoping you from linking to an invisible iframe that will do php processing 4 you.
cwarn23
Occupation: Genius
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
that doesn't do anything. php is putting that to the browser, not the javascript.
view the source of the page. there will be nothing in the write function of the javascript.
how about you accept the truth. its how php works. you would think if that was possible you wouldn't be the first one to figure it out. you really need to explore php more to understand it. then you wouldn't of even posted this in the first place.
javascript CANNOT run a php function, period. you can have the output of a php function in javascript. i think you have this confused. read a php book, and it will show you.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
wow, you are really misunderstanding here. if you look at the source the output of "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG!" will be where the php is. javascript did not write that to the page. it was already there before you TRIED to call it in javascript.
i think you are not understanding how php works. everyone already knows that php can put information into a page. that is what you are doing. you just don't get the fact that javascript did not call the php function directly.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
are you deliberately wasting our time? you would think if this was possible, someone like me who has been developing with php for years would be agreeing with you. here is an example of what you are saying is possible with php and javascript:
<?php
function display( $text ) {
echo $text;
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<form action="somepage.php" method="post">
<input type="text" name="text" onchange="display(this.value)" />
</form>
</body>
</html>
php would not echo that value in the form. not possible.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
i think you are trying to point out the most basic part of php like i said before. you are just putting data into a javascript function. you are not calling a php function from javascript.
you just don't understand exactly what your code does, and you call me a dumbass.
kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194