Skip to content

Javascript Function

2819 Views 3 Replies

0 Members and 1 Guest are viewing this topic.

Image
Javascript Function
on:
#1
I want to add a function to my forum which I am thinking of adding to my footer section
My problem is i wish to use this for a q/a page hiding and showing answers useing the code below
Code: [Select]
<button onclick="myFunction()">Click Me</button>

<div id="myDIV">
  This is my DIV element.
</div>
[/color][/color]
Code: [Select]
function myFunction() {
  var x = document.getElementById("myDIV");
     if (x.style.display  === "none") {
    x.style.display = "block";
  } else {
    x.style.display =    "none";
  }
}
What I am thinking of doing but not sure if it will work is alter the call and the document.getElementById("myDIV");Like
Code: [Select]
<button onclick="myFunction(dv1)">Click Me</button>

<div id="dv1">
  This is my DIV element.
</div>

And update the function so:
Code: [Select]
function myFunction(myDIV) {
  var x = document.getElementById(myDIV);
     if (x.style.display  === "none") {
    x.style.display = "block";
  } else {
    x.style.display =    "none";
  }
}

Would this work?
Image
Image
Re: Javascript Function
Reply #1 on:
#2
Got this workng with a few minor issues which I'm sure I can sort
Image
Image
Re: Javascript Function
Reply #3 on:
#4
Just in case anybody else wants to do something like this you can use the below
Add this function to your Footer section Style Manager->Headers and footers
Code: [Select]
<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>
Past this into a page to see it work
Code: [Select]
<div class="cat_bar">
<h3 class="catbg centertext" style="text-align: left;"><span style="font-size: small;" title="Click to view answer" onclick="toggle_visibility('DD0')">What software do you use to build database's<br /></span></h3>
</div>
<div id="DD0" style="display: none; text-align: left;">We use Microsoft Access for all our database's, We have also worked with mysql, PHP and Visual Basic</div>
P.S One thing I itend doing is making the click text look like a link
Last Edit: November 29, 2020, 03:31:38 pm by mickjav
Image
 

Related Topics

Image