Page 1 of 1

Integrated PHP and Javascript

Posted: Fri Mar 16, 2007 7:36 am
by S_henry
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 ?>');
}

Posted: Fri Mar 16, 2007 7:37 am
by volka
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

Posted: Sun Mar 18, 2007 9:39 pm
by S_henry
OK. I'll check it out. Thanks Mr. volka.