I want to log a user input form into a text file on server, As well onclick button triggers a function gives a status result from another server, which works well. how can I let a button trigger 2 functions right. If I use submit type button the return function doesn't work. how do I fix these to work together on one click?
html:
<form action="" method="POST"><input class="input" type="text" name="search" id="search" value="" size="13" height="20" width="150" maxlength="13" id="ItemCodeNoPopup" dir="ltr" autocomplete="on">
<input type="button" value="חפש" name="button" align="absmiddle" border="0" alt="submit" onclick="showDiv(); logger();"></form>
post.js:
document.getElementById('quickContactForm')
$(document).ready(function(){
//$("#hiddenDiv").hide();
});
function showDiv(){
var str=$("#search").val();
var url="action.php?show="+str;
console.log('url'+url);
$.get(url,function(data,status){
// alert("Data: " + data + "\nStatus: " + status);
$("#hiddenDiv").html(data);
$("#hiddenDiv").show();
});
function logger(){
var str=$("#search").val();
currentTime = new Date().getTime();
console.log(currentTime);
data = [currentTime,str];
$.post('logger.php',function(data){
});
}
action.php works well.
logger.php
<?php
$Date = date('Y-m-d H:i:s');
var str=$("#search").val();
var ip=$_SERVER['REMOTE_ADDR'];
$file = fopen("log.txt","a+");
fwrite($file,$str,$ip);
fwrite($file,$Date. "\n");
fclose($file);
print_r(error_get_last());
}
?>
If logger.php doesn't depend on result of action.php I suggest to call logger.php in action.php. So you don't need to make two http reqeusts to server. Only one is necessary.
Action.php:
require_once('logger.php')