News:

Create A Forum Installed

Author Topic: Javascript Function  (Read 1456 times)

0 Members and 1 Guest are viewing this topic.

Offline mickjav

  • Full Member
  • ***
  • Posts: 249
  • Karma: 4
  • Gender: Male
  • Database designer
  • Location: Margate, Kent
    • View Profile
    • Database Dreams

Badges: (View All)
Second year Anniversary Level 5 100 Posts
Javascript Function
« 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?

Share on Facebook Share on Twitter


Offline mickjav

  • Full Member
  • ***
  • Posts: 249
  • Karma: 4
  • Gender: Male
  • Database designer
  • Location: Margate, Kent
    • View Profile
    • Database Dreams

Badges: (View All)
Second year Anniversary Level 5 100 Posts
Re: Javascript Function
« Reply #1 on: November 29, 2020, 12:43:09 pm »
Got this workng with a few minor issues which I'm sure I can sort

Offline CreateAForum

  • Administrator
  • *****
  • Posts: 7186
  • Karma: 327
    • View Profile

Badges: (View All)
Avatar Linux User Tenth year Anniversary
Re: Javascript Function
« Reply #2 on: November 29, 2020, 03:00:49 pm »
Nice work!
Like Create A Forum? Support me at https://www.patreon.com/vbgamer45/

Offline mickjav

  • Full Member
  • ***
  • Posts: 249
  • Karma: 4
  • Gender: Male
  • Database designer
  • Location: Margate, Kent
    • View Profile
    • Database Dreams

Badges: (View All)
Second year Anniversary Level 5 100 Posts
Re: Javascript Function
« Reply #3 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
« Last Edit: November 29, 2020, 03:31:38 pm by mickjav »

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
634 Views
Last post August 24, 2011, 07:13:38 pm
by simply sibyl
1 Replies
562 Views
Last post June 17, 2012, 04:52:18 pm
by Andrew
11 Replies
2365 Views
Last post April 07, 2013, 01:54:18 am
by aIURbliS
1 Replies
552 Views
Last post February 13, 2018, 02:14:51 pm
by CreateAForum
2 Replies
403 Views
Last post February 27, 2024, 03:29:30 pm
by CAF-User1