0

Im sure this has been discussed endless times but I can't find anything which will do it how I want to.

I want to seemlessly execute some PHP onclick. It will just update a row in MySQL and I dont want the user to be aware of this happening.

How would I do this?

Im a complete Javascript newbie by the way.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by essential
0

Im not sure if this is what you need. But this trick wil work in some cases.
Assuming that you have the following php function in your page

<html>
<head>
<title></title>
<?php
function changeBg() {
$bgColour = $_REQUEST['demo'];
if(!isset($bgColour)): 
   echo $bgColour; 
else: 
echo '#fff';
endif; }

echo '<style type="text/css">';
echo 'body { background-color: '.changeBg().'; }</style>';
?>
<script type="text/javascript">
<!--
function bcolor() {
var ua = (document.all) ? document.forms['myform'] : document.getElementById('myform');
try { 
ua.demo.value = this.title;  
if (ua.demo.value === this.title) {
return ua.submit(); }
else { window.location.href = "<?php echo $_SERVER['PHP_SELF']; ?>"; } } catch(e) { } } 
//-->
</script>
</head>
<body>
<form id="myform" action="<?php echo $_SERVER['PHP_SELF']; ?>" metho="post">
<div>
<input type="hidden" name="demo" id="demo" />
</div>
</form>
<p>Change the background of this page to <a href="javascript:bcolor();" title="black">black</a>.</p>
</body>
</html>
This topic has been dead for over six months. 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.