Reputation: 13
I am able to open a modal window when clicking on the anchor tag. The onClick function that I am running doesn't seem to be getting called however. I want to be able to have the modal window pop up and add an image to it through the Javascript. The following is the applicable code:
HTML
<a href="#openModal" class="submitBtn" onclick="return displayPhoto();">Submit</a>
<div id="openModal" class="modalDialog">
<div>
<table>
<tr height="500px">
<td id="photo"></td>
<td id="description">
</td>
</tr>
</table>
</div>
</div>
CSS
.modalDialog {
position: fixed;
font-family: Arial, Helvetica, sans-serif;
top: 0;
right: 0;
bottom: 0;
left: 0;
background: rgba(0,0,0,0.8);
z-index: 99999;
opacity:0;
-webkit-transition: opacity 400ms ease-in;
-moz-transition: opacity 400ms ease-in;
transition: opacity 400ms ease-in;
pointer-events: none;
}
.modalDialog:target {
opacity:1;
pointer-events: auto;
}
.modalDialog > div {
width: 600px;
position: relative;
margin: 5% auto;
padding: 5px 20px 13px 20px;
border-radius: 10px;
background: #fff;
background: -moz-linear-gradient(#fff, #999);
background: -webkit-linear-gradient(#fff, #999);
background: -o-linear-gradient(#fff, #999);
}
#photo{
width:auto;
}
Javascript
function displayPhoto(){
window.alert(11);
document.getElementById('photo').innerHTML = "<img src="images/characters/gandalf.jpg" />";
return true;
}
Upvotes: 1
Views: 74
Reputation: 3765
Here is a JSFiddle. As @Maverick pointed out, you had a string error with your getElementById line.
http://jsfiddle.net/tz1att9j/5/
function displayPhoto(){
alert(11);
document.getElementById('photo').innerHTML = "<img src='images/characters/gandalf.jpg' />";
return true;
}
Upvotes: 0
Reputation: 3059
You need to escape your quotes in the innerHTML
document.getElementById('photo').innerHTML = "<img src=\"images/characters/gandalf.jpg\" />";
Upvotes: 3