Page 1 of 1
Giving a PHP Var the value of a JS Var.
Posted: Tue Oct 31, 2006 5:44 pm
by JellyFish
I tried:
Code: Select all
command.innerHTML = "<? insertMessage(" + message + "); ?>";
and all it does give it the value of " + message + ". Why? I mean it's only logical that when I use another double, that javascript should know that I'm ending the string and adding a value of a variable. Why does this do this and how can I make this work?
Posted: Tue Oct 31, 2006 5:58 pm
by feyd
PHP parsed it long before Javascript even knew what was there.
edit: spelling oops.
Posted: Tue Oct 31, 2006 6:27 pm
by JellyFish
Oh I see. Well how do I do this correctly:
Code: Select all
<html>
<head>
<?
function insertMessage($message)
{
$connection = mysql_connect("db2.awardspace.com:3306", "figaro_figaro", "mokicat") or die(mysql_error());
mysql_select_db('figaro_figaro') or die('Could not select database');
$sql = "INSERT INTO IMGClient (message) VALUES ('$message')";
$results = mysql_query($sql, $connection);
}
?>
<script>
function onLoad()
{
command = document.getElementById("command");
}
function sendMessage(message)
{
command.innerHTML = "<? insertMessage(" + message + "); ?>";
}
</script>
</head>
<body onload="onLoad();">
<textarea id="messages" cols="50" rows="10"></textarea></br>
<textarea id="message" cols="50" rows="1"></textarea><button style="position:relative; top: -10; height:30;" onclick="return sendMessage(document.getElementById('message').value);">Send</button>
<div id="command"></div>
</body>
</html>
How do I place the value of the JS variable message in between the brackets of the php function:
Code: Select all
command.innerHTML = "<? insertMessage(" + message + "); ?>";
???
Posted: Wed Nov 01, 2006 12:16 am
by Chris Corbyn
AJAX
Posted: Wed Nov 01, 2006 12:18 am
by aaronhall