I'm quite new to JavaScript so I hoped I could get some help with these questions. I need to save a JavaScript variable (Just a simple number) to a database. I also need to be able to see the current value on 2 websites (using PHP to retrieve it on the second website).
My code now:
Voorraad: <input id="stock1" type=text" style="width:30px" value="10">
<input type="submit" value="Kopen" onclick="javascript:Kopen(event);">
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
function Kopen(e)
{
e.preventDefault();
var stock1 = document.getElementById("stock1");
var newNumber = parseInt(stock1.value) - 1;
stock1.value = newNumber;
if (stock1.value <= 0) {
stock1.value = 0;
}
I know I will need to use AJAX to do this, I have seen a question that is similar but it lacks a database connection and I am not sure how to use those pieces of code: Question
My questions are; How do I write a JavaScript variable to (mysql)database using ajax?