Create A Forum - Support Forums

Support => Create a Forum Codes and Support => Topic started by: mickjav on November 29, 2020, 11:52:07 am

Title: Javascript Function
Post by: mickjav on November 29, 2020, 11:52:07 am
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?
Title: Re: Javascript Function
Post by: mickjav on November 29, 2020, 12:43:09 pm
Got this workng with a few minor issues which I'm sure I can sort
Title: Re: Javascript Function
Post by: CreateAForum on November 29, 2020, 03:00:49 pm
Nice work!
Title: Re: Javascript Function
Post by: mickjav on November 29, 2020, 03:23:05 pm
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