Integrated PHP and Javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Integrated PHP and Javascript

Post 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 ?>');
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
S_henry
Forum Contributor
Posts: 148
Joined: Sun Jan 25, 2004 10:25 pm
Location: M'sia

Post by S_henry »

OK. I'll check it out. Thanks Mr. volka.
Post Reply