Hi I am new to JavaScript and AJAX.
The idea for this page is that when the user clicks the appropriate area in an image in a map it calls a JavaScript function myFunction1 when the entry in 'field_X' is '0' - this function then updates 'field_X' to be '1' through AJAX ('field_X' starts with a '0' entry).
Then when the user next clicks the same area in the map myFunction2 is called because the entry in 'field_X' is now '1' - and this then updates 'field_X' to be '2'.
And so on...
The AJAX call works fine and updates 'field_X' correctly when the appropriate function is called individually.
However the problem is (with the code as I have it) when the user clicks the map all 3 functions are called in succession straight away (and 'field_X' becomes '3'). I am not sure how to pause this between functions and wait for the next click by the user.
I have abbreviated the code in the functions as best I can as the functions do other things as well. Any help would be appreciated.
PHP user page
<?php function request_data(){select field_X from TABLE_X; }
$q = request_data(); ?>
<map>
<area onclick= <?php
if ($q == '0') {?>"myFunction1();" <?php }
if ($q == '1') {?>"myFunction2();" <?php }
if ($q == '2') {?>"myFunction3();" <?php }
if ($q == '3') { ...and so on... }
?> />
</map>
JavaScript page
<script>
//JavaScript
function myFunction1() { update_1(); }
function myFunction2() { update_2(); }
function myFunction3() { update_3(); }
//AJAX - abbreviated
function update_1(){ update TABLE_X set field_X = (1); }
function update_2(){ update TABLE_X set field_X = (2); }
function update_3(){ update TABLE_X set field_X = (3); }
</script>