So, in my code I have this input of type "Image".
<div class="icon" id="button_dictionary">
<form>
<input class="buttonDictionary" type="image" src="icone_dicionario.jpg" value="" id="inputDictionary">
<label for="inputDictionary">Dictionary</label>
</form>
</div>
And I want that, when the user clicks on it, the following form appears:
<form action="http://www.google.pt/search" id="form-dictionary">
(...)
</form>
I've made a Javascript function to make it happens:
function showsDictionaryForm(){
if(document.querySelector('#form-dictionary').style.display == "none")
document.querySelector('#form-dictionary').style.display = "inline-block";
else
document.querySelector('#form-dictionary').style.display = "none";
}
The problems is when I try to deal with the onClick event, so that, when it happens, the function above is called. The function is working pretty well, since for "submit" input types, it works.
Solutions that didn't work:
I tried something like this:
document.querySelector('#button_dictionary').onclick = showsDictionaryForm;
and also this, adding return false the the end of the function.
<input class="buttonDictionary" type="image" src="icone_dicionario.jpg" value="" id="inputDictionary" onClick="showsDictionaryForm()">
None of them worked well. The form appears, but disappears as fast as. It seems to me that the form is calculated, but when the button is submitted, the page is reloaded os something like it, and it disappears again.
showsDictionaryForm()you've set#form-dictionnario, but you use#form-dictionnarywith a -Y, is it ok ?