Javascript dissapearing

Javascript dissapearing

by Amalia Gil -
Number of replies: 1

I am trying to insert a Javascript toggle function into the html editor that looks like this

<a href="javascript: toggle2()"><strong>View Coordinates</strong></a>
  <div id="div2" style="display: none">
    <p>Selecting this tool and clicking on the map gives the coordinates of the point.</p> </div>
  <script>
function toggle2(){
                var div2 = document.getElementById('div2')
                if (div2.style.display == 'none') {
                                div2.style.display = 'block'
                } else {
                                div2.style.display = 'none'
                }
}

</script>  

When I click  to save and display, the function works perfectly, yet when I try to edit the page again, the script is gone. I still have the top part of the script :

<a href="javascript: toggle2()"><strong>View Coordinates</strong></a>
  <div id="div2" style="display: none">
    <p>Selecting this tool and clicking on the map gives the coordinates of the point.</p> </div>

but my javascript function is gone and only the <script></script> appears.

Does anyone know how to make the script stay in the html editor?

Average of ratings: -