So, Below is my JQuery code. I'm simply trying to change the inAddMode
boolean variable to the opposite of what it is when my button with id add_button
is pressed. The alert box is there for testing, but it never triggers when I press add_button
button. Any ideas why this is not working. add_button
is an image, Would that affect it?
var inAddMode = false;
$(document).ready(function(){
$('#add_button').click(function(){
inAddMode = !inAddMode;
alert(inAddMode);
});
//For Adding events on the map
$('#map').click(function(e){
if(inAddMode){
var img = $('<img src="img/map_pin.png" />');
var mapWidth = $("#map_img").width();
var mapHeight = $("#map_img").height();
//Must keep the pixel ratio of original image constant
var mapPinWidth = mapWidth*(0.08);
var mapPinHeight = mapPinWidth;
var offsetLeft = mapPinWidth/2;
var offsetTop = mapPinHeight;
img.css({
position: 'absolute',
width: mapPinWidth,
height: mapPinHeight,
left: e.pageX-offsetLeft,
top: e.pageY-offsetTop,
cursor: 'pointer'
});
$("#map").append(img);
//Now make the app take you to the event creation page
}
});
//end of addMode
});
Full HTML Code
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/app.js"></script>
</head>
<body>
<!--<img src="img/map_north.PNG" style="width: 100%;height: 45%;">
<img src="img/map_south.PNG" style="width: 100%; height: 45%;">
-->
<div id="map">
<img id="map_img" src="img/map.PNG" style=" position: relative; width: 100%;height: auto; border-style: solid">
<script>
var mapWidth = $('#map_img').width();
var mapHeight = $('#map_img').height();
var addSignWidth = mapWidth*(0.04);
var addSignHeight = addSignWidth;
var addSign = $('<img src="img/add_img.png" >');
var offsetLeft = addSignWidth;
var offsetTop = addSignHeight;
addSign.css({
id: 'add_button',
position: 'absolute',
width: addSignWidth,
height: addSignWidth,
left: mapWidth-offsetLeft - mapWidth*(0.001),
top: mapHeight*(0.04) ,
cursor: 'pointer'
});
$("#map").append(addSign);
</script>
<!---<img src="img/add_img.png" style=<script>getAddButtonInfo()</div>>-->
</div>
</body>