Ok, so I have the following HTML:
<a href="#" onclick="bump_add('.$fetch['photo_id'].')">
<img id="bump_img" src="img/bump.png"/>
</a>
Currently my Javascript/Ajax looks like this:
function bump_add(photo_id) {
$.post('php/bump_add.php', {photo_id:photo_id}, function(data){
if (data='success') { //Handled by PHP
bump_get(photo_id);
toggle_visibility('bump_img')
} else {
alert(data);
}
});
}
function bump_get(photo_id) {
$.post('php/bump_get.php', {photo_id:photo_id}, function(data){
$('#photo_'+photo_id+'_bumps').text(data); //Handled by PHP
});
}
function toggle_visibility(id) {
var e = document.getElementById(id);
if(e.style.display == 'block') {
e.style.display = 'none';
}
}
I'm not great at Javascript, so I'm not entirely sure how to achieve my objective.
What I'm trying to do is run the bump_add() function on the 'onclick' event (which works), followed by the bump_get() function (which also works). But then to finally run the toggle_visibility() function, this bit doesn't work.
Any ideas as to what I'm doing wrong? Is the Javascript function for toggle_visibility() incorrect, or am I just using it incorrectly? The aim of it is to hide the img with the 'bump_img' id.