Click to See Complete Forum and Search --> : PHP onclick event


imname
January 22nd, 2008, 04:28 AM
I would like to write "1234" to Command.txt when I click the OKbutton.
However I cant get what I expected...anyone can help me please???


<?php
function WriteCommFile($command){
$file="Command.txt";
$handle = fopen($file, "w+");
if($handle==false){
die("unable to create file");
}else{
$data=$command;
fwrite($handle,$data);
fclose($handle);
}
}

echo "<button onclick='WriteCommFile(1234)'>OK</button>";

?>

Homogenn
January 22nd, 2008, 05:13 AM
I would like to write "1234" to Command.txt when I click the OKbutton.
However I cant get what I expected...anyone can help me please???


<?php
function WriteCommFile($command){
$file="Command.txt";
$handle = fopen($file, "w+");
if($handle==false){
die("unable to create file");
}else{
$data=$command;
fwrite($handle,$data);
fclose($handle);
}
}

echo "<button onclick='WriteCommFile(1234)'>OK</button>";

?>


I think you're confusing server side scripts with client side scripts. You can't make the button call a server-side function. Instead you can use forms to send whatever info you need to your page.

http://www.w3schools.com/php/php_post.asp

PeejAvery
January 22nd, 2008, 10:14 AM
To best resemble the onclick event, you might want to try posting with AJAX.

imname
January 24th, 2008, 10:32 PM
thank you...