I am trying to make a query to an SQL database and I can't figure out why my code won't work. When I call the javascript function:
function calledfunction(){
var date = new Date(document.getElementById("datetime1").value);
var dateformat = "'"+date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() +":" + date.getMinutes()+"'";
alert("Value is: " + dateformat);
microAjax("genjsonphp.php?stdt="+dateformat, function(data) {
//edited out
}
I get the alert: Value is: '2011-12-6 0:0'
When I copy the value in the alert and paste it so the above code becomes:
function calledfunction(){
var date = new Date(document.getElementById("datetime1").value);
var dateformat = "'"+date.getFullYear() + "-" + (date.getMonth()+1) + "-" + date.getDate() + " " + date.getHours() +":" + date.getMinutes()+"'";
alert("Value is: " + dateformat);
dateformat = '2011-12-6 0:0';
microAjax("genjsonphp.php?stdt="+dateformat, function(data) {
//edited out
}
Then the code works fine. Does anyone have an idea what is going wrong?
microAjax("genjsonphp.php?stdt="+encodeURIComponent(dateformat), function(){});