Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
107
rated 0 times [  111] [ 4]  / answers: 1 / hits: 24299  / 11 Years ago, sat, may 18, 2013, 12:00:00

I thought doing something like this would have worked, but I'm confused as to why it isn't when the style is hiding the image to begin with, but not showing it when the button is pressed. Here's the code:



function showImg() {
x=document.getElementById(map_img)
x.style.visibility=visible;
}

<body>
<img id=map_img src=map.jpg style=visibility:hidden width=400 height=400/>

<form id=form1 name=form1 align=center>
<input type=submit id=Map value=Map onclick=showImg()/>
</form>


I've also tried this in both situations:



<input type=button id=Map value=Map onclick=showImg()/>


and:



<style>
.hidden{display:none;}
.show{display:block;}
</style>

function showImg() {
x=document.getElementById(map_img)
x.class=show;
}

<body>
<img id=map_img src=map.jpg class=hide width=400 height=400/>

<form id=form1 name=form1 align=center>
<input type=submit id=Map value=Map onclick=showImg()/>
</form>


I'm really lost as to how neither of these worked, could I get some help on this please?


More From » javascript

 Answers
34

You shouldn't* wrap the input element in a form if you don't want the standard submit behavior.



In your code as written, the form triggers a page load or an error, which prevents the script from running.


[#78151] Thursday, May 16, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
robinh

Total Points: 371
Total Questions: 105
Total Answers: 89

Location: Cyprus
Member since Mon, Oct 24, 2022
2 Years ago
;