Click to See Complete Forum and Search --> : Inserting Javascript Variables into DB using PHP


Arc
05-18-2003, 04:19 PM
Hi, i have a javascript function that opens a new window and at the same time uses php to write a couple variables to a database. The window opens and the php writes to the database but it's not writing the value of the javascript variable i am trying to asign to it.

here's my code.




function MM_openBrWindow(theURL,winName,features) { //v2.0
var title = document.form.txtEventTitle.value;
var info = document.form.txtEventInfo.value;
<?php
$conn = db_connect("dbname");
$Sql = "UPDATE tblTmpEvents SET EventTitle='title', EventInfo='info'";
$Result = mysql_query($Sql);
?>
win = window.open(theURL,'emailWin',features);
win.focus();
}



As you can see i am setting the variables title and info to the values of 2 text boxes on my form. I then want to write these variables to the database but i cant figure out how to get the value of those variables into the php code.

How would i go about this?

Thanks!

pyro
05-18-2003, 04:24 PM
There are two ways to move a javascript variable to a PHP page. One is by submitting a form, and two is by refreshing the page with a query string (page.htm?variable). You can't just call your javascript variable as a PHP variable.

ApletFX
11-19-2003, 10:50 PM
pyro - no wonder your the "Super Moderator" You solved a problem I have been trying to figure out for three days. The fact that I would have to submit a form to use a variable seams so out of wack but works like a charm. With this I have finaly put an end to a major part of my message board. :D

thanks again!

pyro
11-19-2003, 10:54 PM
You can do the same with a regular link:

<a href="page.php?foo=value">test</a>

AND:

$foo = $_GET['foo']; //equals values

;)

ApletFX
11-19-2003, 11:09 PM
This is pretty nifty...


<form name="prevform" method="post">
<input type="hidden" name="message">
<input name="action" type="hidden" id="action" value="show">
</form>

<script language="javascript">
document.prevform.message.value=window.opener.document.PostTopic.message.value;
document.prevform.submit();
</script>


This will take my form info from a preview button and allow me to post it as form data and apply my string manipulations to the form data wich is great because my JS skills are pretty low. :o