php-code in javascript

This is a discussion on php-code in javascript within the PHP General forums, part of the PHP Programming Forums category; hello everybody, I have a newbie question: Is it possible to use php-code in een javascript function? In this ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-13-2005
edt
 
Posts: n/a
Default php-code in javascript

hello everybody, I have a newbie question:
Is it possible to use php-code in een javascript function?
In this way the messages are deleted, but the alert en confirm windows don't
apper.
Something like:

<!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=iso-8859-1"/>
<style type="text/css" media="screen"><!--
--></style>

<script language="JavaScript" type="text/javascript">
function delete_message() {
var win=window.confirm("Do you want to delete this message?")
if(win==true) {
<?php
php-code to connect to the database and to delete a record
?>
window.alert("Message deleted!")
}else{
window.alert("The message is not deleted.")
}
}
</script>
</head>
<body>
<a href="#" onClick="skip_bericht()">delete</a>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 08-13-2005
Ken Robinson
 
Posts: n/a
Default Re: php-code in javascript


edt wrote:
> hello everybody, I have a newbie question:
> Is it possible to use php-code in een javascript function?
> In this way the messages are deleted, but the alert en confirm windows don't
> apper.
> Something like:
>
> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"/>
> <style type="text/css" media="screen"><!--
> --></style>
>
> <script language="JavaScript" type="text/javascript">
> function delete_message() {
> var win=window.confirm("Do you want to delete this message?")
> if(win==true) {
> <?php
> php-code to connect to the database and to delete a record
> ?>
> window.alert("Message deleted!")
> }else{
> window.alert("The message is not deleted.")


Remember, PHP executes on the server and Javascript on the client. In
your example, by the time the client sees you Javascript code, PHP has
is all done. The only way I know that can do what you want is to use
Javascript XMLHttp methods to start another PHP script and wait for it
to finish.

Ken

Reply With Quote
  #3 (permalink)  
Old 08-20-2005
edt
 
Posts: n/a
Default Re: php-code in javascript

Ken Robinson wrote:

>
> edt wrote:
>> hello everybody, I have a newbie question:
>> Is it possible to use php-code in een javascript function?
>> In this way the messages are deleted, but the alert en confirm windows
>> don't apper.
>> Something like:
>>
>> <!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN"
>> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
>> <html xmlns="http://www.w3.org/1999/xhtml">
>> <head>
>> <meta http-equiv="content-type" content="text/html;charset=iso-8859-1"/>
>> <style type="text/css" media="screen"><!--
>> --></style>
>>
>> <script language="JavaScript" type="text/javascript">
>> function delete_message() {
>> var win=window.confirm("Do you want to delete this message?")
>> if(win==true) {
>> <?php
>> php-code to connect to the database and to delete a record
>> ?>
>> window.alert("Message deleted!")
>> }else{
>> window.alert("The message is not deleted.")

>
> Remember, PHP executes on the server and Javascript on the client. In
> your example, by the time the client sees you Javascript code, PHP has
> is all done. The only way I know that can do what you want is to use
> Javascript XMLHttp methods to start another PHP script and wait for it
> to finish.
>
> Ken

Ken, thanks for the answer! I will try it the other way.
Ed
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:58 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0