0

I don't think that is of any use. He is not going to listen/see. He only wants to hear what he wants to hear. :)

Is there anything wrong with my proposition?
I showed you how to call php function and trigger the javascripts events.

1. myfunction() is php function.
2. I call transfer to javascript()
3. trigger the button.

What is wrong with that?

If you have something in your mind or any idea just keep it to yourself and make your own proposition later. I told you guys take it or leave it.

0

Cwarn23, If you read all the posts, you will see I have no where insulted him. I am just giving a dose of his own medicine, in a sarcastic way.
As I already said in my previous post, he had no respect whatsoever for the other posters. I don't expect that from a new member (and I am sure most of the people here agree with me).
I also think there is a limit for everything. He (rm_daniweb) has surely crossed it.

if you really read the thread I was not the one who started to use nasty words! right?

YOU ARE BARKING AT THE WRONG TREE!

0

Cwarn23, If you read all the posts, you will see I have no where insulted him. I am just giving a dose of his own medicine, in a sarcastic way.
As I already said in my previous post, he had no respect whatsoever for the other posters. I don't expect that from a new member (and I am sure most of the people here agree with me).
I also think there is a limit for everything. He (rm_daniweb) has surely crossed it.

The only thing is that when you put that into an equation it doesn't exactly add up. An example equation is rm_daniweb's number of post devided by your number of post which would be the percentage of return abbuse if you want to put it that way:

23/3497=0.00645
Above is the ration then convert to percent
0.0064577*100=0.64%

So using that equation 0.64% is the percentage of abuse you can send back to him although I would not recommend it. Just one way looking at it.

how about if the JAVASCRIPT function is refreshing a new PHP page or loading a NEW PHP page and that page IS FULL OF PHP COMMANDS. What will happen....like location.etc...header() in php....

Just let us explore the possibilitiies...

Well there is one option for 2 way processing is the following script:

index.html:

<head><title>Tester</title></head><body>
<form method='post' action='processor.php' target='frame'>
<input type='text' name='value'>
<input type='submit' value='submit'>
</form>
<iframe src ='processor.php' width=1 height=1 marginheight=0 marginwidth=0 scrolling='no' frameborder=0 name='frame'>
</iframe>
</body>

processor.php

<?
if (isset($_POST)) {
//do php processing with the form
}
?>

That is a more realistic way of getting the client to communicate with the server.

0

Just let him think what he wants and live in his own little world. After countless times of explanation, he still doesn't get it.

Lets stop replying. Forever.

0

Just let him think what he wants and live in his own little world. After countless times of explanation, he still doesn't get it.

Lets stop replying. Forever.

Yeah! That is what I am gonna do from now on. I value my precious time :)

0

Just let him think what he wants and live in his own little world. After countless times of explanation, he still doesn't get it.

Lets stop replying. Forever.

Yes, you are very true only sensible and analytical people can fit into my world. Indeed I have a small world. Because there are only few people can understand what I mean and you are not lucky to be one of them.

I told you...before:

Is there anything wrong with my proposition?
I showed you how to call php function and trigger the javascripts events.

1. myfunction() is php a function.
2. echo inside my function is also php function.
3. I call it transfer the arguments to javascript()
4. trigger the events button.
5. it works!!!

Wow! cool! forever no reply I love it dud!

My proposition is simple....but all of you make it complicated.

0

Yeah! That is what I am gonna do from now on. I value my precious time :)

I don't think you have precious time. People like you usually are wasting time. And actually you are wasting my time.

0

Since how I have the rest of the night to wast, I will try and invent a proper way of javascript communicating with php using 1 iframe + cookies.

0

For the future rm_daniweb, nav33n and kkeith29 we do not wish to see any of such confrontations as in this thread.
If original poster is unwilling to listen to your advice you better of with ignoring any further queries.
For the original poster, if you get reply you are doing something wrong please try out suggested solution before you start abusing people that are trying to help you.

0

SORRY TO ALL GUYS!!!

ACTUALLY HERE'S THE CODE OF RUNNING PHP...IN ONCLICK...

//RUN THIS ON YOUR MYSQL

CREATE TABLE `php_to_js` (
  `srno` int(11) NOT NULL auto_increment,
  `u_name` varchar(50) default NULL,
  `u_email` varchar(55) default NULL,
  PRIMARY KEY  (`srno`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `php_to_js` VALUES ('1', 'name1', 'name1@yahoo.com');
INSERT INTO `php_to_js` VALUES ('2', 'name2', 'name2@yahoo.com');
INSERT INTO `php_to_js` VALUES ('3', 'name3', 'name3@yahoo.com');
INSERT INTO `php_to_js` VALUES ('4', 'name4', 'name4@yahoo.com');
INSERT INTO `php_to_js` VALUES ('5', 'name5', 'name5@yahoo.com');


==================================================================



'name the file below javatomysql.php'

<html>
<head>
<script language="JavaScript"><!--
//these function from:
//http://www.devshed.com/c/a/PHP/PHP-and-JavaScript-Pooling-Your-Resources/
//this function calls the child file
function attach_file( p_script_url ) {
// create new script element, set its relative URL, and load it
script = document.createElement( 'script' );
script.src = p_script_url;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

//this function updates the status box
function show_status( status_text ) {
document.getElementById('status').innerHTML = status_text;
}
//-->
</script>
<title>PHP MySQL and Javascripts Working Together </title>
<!-- CSS Details -->
<style type="text/css">
<!--
.table1 {
border: 1px solid #CC6600;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
text-transform: none;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 8px;
background-position: center top;
margin: 0px;
padding: 15px;
}
input {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
font-weight: bold;
font-variant: normal;
color: #0099CC;
background-color: #FFFFCC;
border: 1px solid #FF9900;
}
.row1 {
background-color: #CCFFCC;
}
.style1 {
color: #FFFFFF;
font-weight: bold;
}
.row2 {
background-color: #FFFFFF;
}
-->
</style>
</head>

<body onLoad="javascript:attach_file( 'mysql_insert.php' ) ; show_status('Ready...'); ">
<table width="600" border="0" cellpadding="1" cellspacing="3" class="table1">
<tr>
<td width="88">Status Box: </td>
<td width="493" bgcolor="#CCCCCC"><span id="status" /></span> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Name</td>
<td><input name="u_name" type="text" id="u_name" size="40" maxlength="40"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="u_email" type="text" id="u_email" size="40" maxlength="45">
(email MUST contain the '@' and '.') </td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="Button" value="Click Here to Insert into Mysql..." onClick="javascript:attach_file( 'mysql_insert.php?u_name=' + u_name.value + '&u_email=' + u_email.value) ; show_status('Busy'); "></td>
</tr>
</table>

<br>
Data from MySQL: <br>

<!-- Do not remove this or the table will not show up -->
<span id="from_mysql">
</span>

<br>
</body>
</html>




'name the file below mysql_insert.php'


<?php
header( 'Content-Type: text/javascript' );
//database info: Change password and DB Name
$db = mysql_connect("localhost", "XXXX", "YYYY") or die (mysql_error());
mysql_select_db ("ZZZZ", $db) or die (mysql_error());

//get values if input fields
$u_name = addslashes($_GET['u_name']); //Name
$u_email = addslashes($_GET['u_email']); //Email

//If name and email are NOT empty, insert into mysql
if (strlen($u_name)>1 and strlen($u_email)>1 and strstr($u_email,"@") and strstr($u_email,".") ) {
$insert = mysql_query("INSERT INTO php_to_js (u_name, u_email) VALUES ('$u_name', '$u_email')",$db) or die(mysql_error());
}

//Now Refresh the table at the bottom id=from_mysql
$row_count = 0;
$output = '<table width="600" border="0" cellpadding="3" cellspacing="0" class="table1"><tr><td width="41" align="center" bgcolor="#3366CC"><span class="style1">Srno</span></td><td width="149" align="center" bgcolor="#3366CC"><span class="style1">Name</span></td><td width="384" align="center" bgcolor="#3366CC"><span class="style1">Email</span></td></tr>';
$result = mysql_query("SELECT srno, u_name, u_email FROM php_to_js",$db) or die (mysql_error());
While( $rows = mysql_fetch_array($result)) {
$srno = $rows['srno'];
$u_name = $rows['u_name'];
$u_email = $rows['u_email'];
$row_style = ($row_count % 2) ? "row1" : "row2";
$output .= '<tr class="'.$row_style.'"><td>'.$srno.'</td><td>'.$u_name.'</td><td>'.$u_email.'</td></tr>';
$row_count = $row_count + 1;
}
//Free Results
mysql_free_result($result);
$output .= '</table>';
?>

from_mysql_obj = document.getElementById( 'from_mysql' );
from_mysql_obj.innerHTML = '<? echo $output; ?>';


//update status box
my_status = document.getElementById( 'status' );
my_status.innerHTML = 'Ready...';

//clear values from text fields
document.getElementById('u_name').value = '';
document.getElementById('u_email').value = '';

NOW WE CAN DECLARE IT! SOLVED....GOT YOU!!! :-)
WELCOME! to my small WORLD!!! :-)

0

I have just managed to make basic communication between javascript and php using cookies and an iframe and my script is as follows:
index.html

<head><title>Tester</title>
<script>
function CookieVal(c_name) {
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        { 
        c_start=c_start + c_name.length+1; 
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        window.variable.field.value = unescape(document.cookie.substring(c_start,c_end));
        } 
      }
    window.setTimeout("CookieVal", 900);
    }
function getCookie()
{
document.write("<form name='variable' style='margin:0; padding:0;'><input type='text' name='field' style='border: 0; width: 512px;'></form>");
CookieVal('text');
}</script>
</head><body>
<form method='post' action='processor.php' target='frame'>
Enter a cookie value: <input type='text' name='text'>
<input type='submit' value='submit'>
</form>
<iframe src ='processor.php' width=1 height=1 marginheight=0 marginwidth=0 scrolling='no' frameborder=0 name='frame'>
</iframe> The cookie value was:<br>
<script>getCookie();</script>
</body>

And processor.php

<?
if (isset($_POST)) {
//set the cookie to be display on main page
setcookie ('text',$_POST['text'], time()+3600);

/* do whatever with $_POST values */
}
?>

Also notice that when changing the value of the cookie, the page does not refresh to display the new cookie value and that the php code is executed when the form is submitted. Now thats a propper way of getting php to communicate with javascript.

0

Here's more complex example...using the onclick() calling php function in javascript. The product of research...

//RUN THIS ON YOUR MYSQL

CREATE TABLE `php_to_js` (
  `srno` int(11) NOT NULL auto_increment,
  `u_name` varchar(50) default NULL,
  `u_email` varchar(55) default NULL,
  PRIMARY KEY  (`srno`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

-- ----------------------------
-- Records 
-- ----------------------------
INSERT INTO `php_to_js` VALUES ('1', 'name1', 'name1@yahoo.com');
INSERT INTO `php_to_js` VALUES ('2', 'name2', 'name2@yahoo.com');
INSERT INTO `php_to_js` VALUES ('3', 'name3', 'name3@yahoo.com');
INSERT INTO `php_to_js` VALUES ('4', 'name4', 'name4@yahoo.com');
INSERT INTO `php_to_js` VALUES ('5', 'name5', 'name5@yahoo.com');


==================================================================



'name the file below javatomysql.php'

<html>
<head>
<script language="JavaScript"><!--
//these function from:
//http://www.devshed.com/c/a/PHP/PHP-and-JavaScript-Pooling-Your-Resources/
//this function calls the child file
function attach_file( p_script_url ) {
// create new script element, set its relative URL, and load it
script = document.createElement( 'script' );
script.src = p_script_url;
document.getElementsByTagName( 'head' )[0].appendChild( script );
}

//this function updates the status box
function show_status( status_text ) {
document.getElementById('status').innerHTML = status_text;
}
//-->
</script>
<title>PHP MySQL and Javascripts Working Together </title>
<!-- CSS Details -->
<style type="text/css">
<!--
.table1 {
border: 1px solid #CC6600;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
text-transform: none;
}
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 8px;
background-position: center top;
margin: 0px;
padding: 15px;
}
input {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-style: normal;
font-weight: bold;
font-variant: normal;
color: #0099CC;
background-color: #FFFFCC;
border: 1px solid #FF9900;
}
.row1 {
background-color: #CCFFCC;
}
.style1 {
color: #FFFFFF;
font-weight: bold;
}
.row2 {
background-color: #FFFFFF;
}
-->
</style>
</head>

<body onLoad="javascript:attach_file( 'mysql_insert.php' ) ; show_status('Ready...'); ">
<table width="600" border="0" cellpadding="1" cellspacing="3" class="table1">
<tr>
<td width="88">Status Box: </td>
<td width="493" bgcolor="#CCCCCC"><span id="status" /></span> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td>Name</td>
<td><input name="u_name" type="text" id="u_name" size="40" maxlength="40"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="u_email" type="text" id="u_email" size="40" maxlength="45">
(email MUST contain the '@' and '.') </td>
</tr>
<tr>
<td> </td>
<td><input type="button" name="Button" value="Click Here to Insert into Mysql..." onClick="javascript:attach_file( 

'mysql_insert.php?u_name=' + u_name.value + '&u_email=' + u_email.value) ; show_status('Busy'); "></td>
</tr>
</table>

<br>
Data from MySQL: <br>

<!-- Do not remove this or the table will not show up -->
<span id="from_mysql">
</span>

<br>
</body>
</html>




'name the file below mysql_insert.php'


<?php
header( 'Content-Type: text/javascript' );
//database info: Change password and DB Name
$db = mysql_connect("localhost", "XXXX", "YYYY") or die (mysql_error());
mysql_select_db ("ZZZZ", $db) or die (mysql_error());

//get values if input fields
$u_name = addslashes($_GET['u_name']); //Name
$u_email = addslashes($_GET['u_email']); //Email

//If name and email are NOT empty, insert into mysql
if (strlen($u_name)>1 and strlen($u_email)>1 and strstr($u_email,"@") and strstr($u_email,".") ) {
$insert = mysql_query("INSERT INTO php_to_js (u_name, u_email) VALUES ('$u_name', '$u_email')",$db) or die(mysql_error());
}

//Now Refresh the table at the bottom id=from_mysql
$row_count = 0;
$output = '<table width="600" border="0" cellpadding="3" cellspacing="0" class="table1"><tr><td width="41" align="center" 

bgcolor="#3366CC"><span class="style1">Srno</span></td><td width="149" align="center" bgcolor="#3366CC"><span 

class="style1">Name</span></td><td width="384" align="center" bgcolor="#3366CC"><span class="style1">Email</span></td></tr>';
$result = mysql_query("SELECT srno, u_name, u_email FROM php_to_js",$db) or die (mysql_error());
While( $rows = mysql_fetch_array($result)) {
$srno = $rows['srno'];
$u_name = $rows['u_name'];
$u_email = $rows['u_email'];
$row_style = ($row_count % 2) ? "row1" : "row2";
$output .= '<tr class="'.$row_style.'"><td>'.$srno.'</td><td>'.$u_name.'</td><td>'.$u_email.'</td></tr>';
$row_count = $row_count + 1;
}
//Free Results
mysql_free_result($result);
$output .= '</table>';
?>

from_mysql_obj = document.getElementById( 'from_mysql' );
from_mysql_obj.innerHTML = '<? echo $output; ?>';


//update status box
my_status = document.getElementById( 'status' );
my_status.innerHTML = 'Ready...';

//clear values from text fields
document.getElementById('u_name').value = '';
document.getElementById('u_email').value = '';

Run "javatomysql.php" and input the proper email format.
you will see the new record added on database without refreshing the page!
welcome to my tiny world...

-1

hello mr daniweb.

ive tried your code about the same number of time u have posted it.. and i must say.. its bull****. admin pls remove the thread.

0

Hi All,

I just want to share my code.

A lots of website said that php is on server side and javascript is on client side...they said we cannot run php on javascript...

here's how we can run php function when you click call the onchange events on javascript.

function myfunction(){
$x="I love PHP ! by Arman de Guzman de Castro :-)";
return $x;
}
?>
<!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() {
b = "<?=myfunction();?>";
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();"></form><p>
</body>
</html>

try to type something on the inputbox....
hope you can help me to improve this code of mine..

cheers!

function myfunction(){
      $x="I love PHP ! by Arman de Guzman de Castro :-)";
      return $x; // original
      }
      ?>
function myfunction(){
      $x="I love PHP ! by Arman de Guzman de Castro :-)";
      echo $x; //why not this to get it to work?
      }
      ?>
<!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() {
    b = "<?=myfunction();?>"; // original
    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();"> // original
</form><p>
</body>
</html>
<!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() {
    b = "<? myfunction();?>"; why not this and it works.
    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" onclick="ILovePHP();"></form><p> // I reefer onclick ;) onchange dosent work this way
</body>
</html>

It works and i get at alert boxs with "I love PHP ! by Arman de Guzman de Castro :-)"

but the trick is to change that value and put back to server side php.
now it get though!
if you need to pass that new changed value to your server side php you got to run a settings.php?value=new value "site reloaded" and the only way to do this without xmlhttprequest or jquary or ajax.
and it not easy and a php update with all javascript imploded in php so you not have to use javascript at all that will be nice.

sorry for my bad english.

0

hello mr daniweb.

ive tried your code about the same number of time u have posted it.. and i must say.. its bull****. admin pls remove the thread.

It works on my site! That rm_daniweb code is GREAT!!!

Edited by phpbeginners: n/a

0

este el codigo de php a javascript

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php
function myfunction(){
$x="I love PHP ! by Jesus Landa Peru-)";
return $x;
}
?>
<script language="javascript" type="text/javascript">
function ILovePHP() {
b = '<?php echo myfunction(); ?>';
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 id="armandecastro" name="armandecastro" type="text" onChange="ILovePHP()">
</form>
</body>
</html>

0

LOL This post is old, but it was really fun to read it :-)

Adding a timestamp to the php code shows the magic:

<?php
function myfunction(){
    $timestamp = time();
    $format = date("d.m.Y H:i:s", $timestamp);
    echo "$format: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG!";
}
?>
<!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() {
    document.write('<form action="" method="post"><input name="" type="text" onChange="ILovePHP();"></form><p>');
document.write('<?=myfunction();?>');
}
</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="" type="text" onChange="ILovePHP();"></form><p>
</body>
</html>

Even rm_daniweb would see now, that the time will not change: It will always show the same time, because javascript cannot call PHP, just like everyone here was saying.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.