Good Morning,
related to http://www.codingforum.net/showthrea...873#post799873
Philip M has wrote the code that permit to display for 10 minuts the value "nome" but this code is applied to a button that don't submit 3 values to a mysql DB, i've tried to update his code with submit function but the event "submit" reload the form and i loose the function AddItem.
Following our bible (google) i've found a possible solution with AJAX..
I've tried to modify the script with some tutorials but it's not working
Someone can help me??
)
page add_activity.php
query_activity.php
related to http://www.codingforum.net/showthrea...873#post799873
Philip M has wrote the code that permit to display for 10 minuts the value "nome" but this code is applied to a button that don't submit 3 values to a mysql DB, i've tried to update his code with submit function but the event "submit" reload the form and i loose the function AddItem.
Following our bible (google) i've found a possible solution with AJAX..
I've tried to modify the script with some tutorials but it's not working
Someone can help me??

page add_activity.php
Code:
.... ?> <form name="form1" class="cmxform" id="commentForm" method="post" action=""> <div class="form">ragazza: <? catch_girl($query,$girl); ?> </div> <div class="form">privé: <select class="box" name="prive" id="prive" onFocus="className='focused';" onBlur="className='box';"> <option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> </select> </div> <div class="form" style="padding-top:10px;"><span class="button"> <input type="button" name="activity" value="inserisci" onClick="addItem()"/></span></div> <div><textarea style="background-color:#CCCCCC;" name="girlvalue" cols="20" rows="20" id="girlvalue"> </textarea></div> </form> <script type = "text/javascript"> function ajaxFunction(){ var ajaxRequest; // The variable that makes Ajax possible! ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.myForm.time.value = ajaxRequest.responseText; } } var ragazza = document.getElementById('girl').value; var prive = document.getElementById('prive').value; var day = new Date().getTime(); var queryString = "?girl=" + girl + "&day=" + day + "&prive=" + prive; ; ajaxRequest.open("POST", "query_activity.php" + queryString, true); ajaxRequest.send(null); } var atext = new Array(); var atim = new Array() var otext = "Ragazze Impegnate: \n"; document.getElementById("girlvalue").value = otext; //var showtime = 300000; // milliseconds = 5 minutes var showtime = 600000 // 10 seconds for test purposes window.setInterval("showtext()",1000); // refresh every 1 second function showtext() { var now = new Date().getTime(); var string = otext; for (var i =0; i <= atext.length; i++) { if ((atim[i] + showtime) > now) { string = string + "\n" + atext[i]; string = string.replace(/\s+/g," "); } document.getElementById("girlvalue").value = string; } } function addItem() { var b = document.getElementById("girl").value; atext.push(b); var now = new Date().getTime(); atim.push(now); document.getElementById("girl").value = ""; ajaxFunction(); } </script>
Code:
include 'pagethatcontaindbconnectionanddbselection.php'; // Retrieve data from Query String $girl = $_POST[girl]; $prive = $_POST[prive]; $day = date("d/m/Y"); $hour = date ("H:i"); // Escape User Input to help prevent SQL Injection $girl = mysql_real_escape_string($girl); $prive = mysql_real_escape_string($prive); //build query $query=mysql_query("INSERT INTO nameoftable_activity VALUES (NULL,'".$girl."','".$prive."','".$day."','".$hour."')") or die(mysql_error()); if ($prive == '1') { echo'<script type="text/javascript">openwindow();</script>'; } if ($prive == '2') { echo'<script type="text/javascript">openwindow2();</script>'; } if ($prive == '3') { echo'<script type="text/javascript">openwindow3();</script>'; } ?>
Comment