Hi guys,
In my PHP page, I have 1 Javascript function to compare the value of the textbox with the value in database. In my opinion I have to use PHP in my Javascript function. PHP will be used to retrieve data from database and it will be compared to the value of the textbox (document.form1.txtTest.value;) in my Javascript function. The problem is I don't know how to do it. It always get error. Anybody can help me pls? Thanks.
Example of Javascript function:
function test() {
<?php
$a = ?>document.form1.txtTest.value; <?php ;
?>
alert('<?php echo $a ?>');
}
Integrated PHP and Javascript
Moderator: General Moderators
php runs server-side, javascript client-side. Both are only connected via http requests.
Open your browser's source view and you will find only html and javascript code displayed, but not php code. The php script was already processed by the server and only the output was sent to the client. Therefore you cannot call php functions directly from javascript.
You might be interested in http://en.wikipedia.org/wiki/AJAX
Open your browser's source view and you will find only html and javascript code displayed, but not php code. The php script was already processed by the server and only the output was sent to the client. Therefore you cannot call php functions directly from javascript.
You might be interested in http://en.wikipedia.org/wiki/AJAX