i would like to insert variables into my database, some are php wich works fine, but the problem is the javascript variables, it does not work. im quite new to this any help would be nice.
this is my first question, im sorry if i get the code blocks wrong.
echo '<br>
<form><input type="button" id="startbutton" value="start time control" onClick="starttime()" style="width:225px; margin-top:0px; "><br>
<script type="text/javascript">
var tekst = "";
var startdatum;
var starttijd;
var stopdatum;
var stoptijd;
var startdatumtijd;
function starttime()
{
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
starttijd = d.getHours() + ":" + d.getMinutes();
startdatum=(curr_year + "-" + curr_month + "-" + curr_date);
startdatumtijd = (startdatum + " " + starttijd);
startbutton.value = "stop timecontrol";
startbutton.onclick = timecontrol;
}
function timecontrol()
{
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth() + 1;
var curr_year = d.getFullYear();
tekst = document.getElementById("inputtekst").value;
stoptijd = d.getHours() + ":" + d.getMinutes();
stopdatum=(curr_year + "-" + curr_month + "-" + curr_date);
var stopdatumtijd = (stopdatum + " " + stoptijd);
tx.executeSql("INSERT INTO `vtiger_timecontrol` (`title`,`relconcept`, `relatedto`, `date_start`,`time_start`,`date_end`,`time_end`)VALUES ('.$ticketno.' , \'Support_\' , '.$ticketnummer.' , startdatum , starttijd , einddatum , eindtijd );");
tx.executeSql("INSERT INTO `vtiger_crmentity` (`description`,`setype`,`createdtime`,`modifiedtime`,`viewedtime`)VALUES(tekst,\'Timecontrol\',stopdatumtijd,stopdatumtijd,stopdatumtijd);");
}</script></form>';
What should happen is when i press a button, it saves the time in a variable, the second time i press the button it will save the time in another variable, now i want these time variables to be saved in my database.
Thank you.
Carsten
18.5k4 gold badges52 silver badges56 bronze badges
1 Answer 1
ajax worked:
if (radio2.checked == true)
{
var checked = 0;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("post","tc.php?ticketid='.$ticketnummer.'&ticketnummer='.$ticketno.'&hidden1=" + startdatum+"&hidden2=" + starttijd+"&hidden3=" + stopdatum+"&hidden4=" + stoptijd+"&hidden5=" + tekst+"&hidden6=" + stopdatumtijd + "&hidden7=" + checked, false);
xmlhttp.send();
}
else if (radio3.checked == true)
{
var checked = 1;
xmlhttp = new XMLHttpRequest();
xmlhttp.open("post","tc.php?hidden8='.$current_user.'&ticketid='.$ticketnummer.'&ticketnummer='.$ticketno.'&hidden1=" + startdatum+"&hidden2=" + starttijd+"&hidden3=" + stopdatum+"&hidden4=" + stoptijd+"&hidden5=" + tekst+"&hidden6=" + stopdatumtijd + "&hidden7=" + checked , false);
xmlhttp.send();
}
thank you for the advice.
Sign up to request clarification or add additional context in comments.
1 Comment
Fergus In London
Just seen this, that's awesome you managed to go and get it working based on the pointers in the comments above; congrats!
default
tx? A php variable? :otxis generally the identifier used for examples of the JS API for SQLlite/LocalStorage. I'm guessing there's some copy and pasting going on without quite understanding what's going on.