Author Topic: Javascript Function  (Read 572 times)

0 Members and 0 Guests are viewing this topic.

Offline mickjav

  • Full Member
  • ***
  • Posts: 240
  • Karma: 4
  • Gender: Male
  • Database designer
  • Location: Margate, Kent
    • View Profile
    • Database Dreams
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: 240
  • Karma: 4
  • Gender: Male
  • Database designer
  • Location: Margate, Kent
    • View Profile
    • Database Dreams
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

Online CreateAForum

  • Administrator
  • *****
  • Posts: 6539
  • Karma: 303
    • View Profile
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: 240
  • Karma: 4
  • Gender: Male
  • Database designer
  • Location: Margate, Kent
    • View Profile
    • Database Dreams
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
290 Views
Last post June 17, 2012, 04:52:18 pm
by Andrew
11 Replies
2046 Views
Last post April 07, 2013, 01:54:18 am
by aIURbliS
2 Replies
457 Views
Last post June 04, 2014, 04:07:14 pm
by Pinkparsnip
1 Replies
278 Views
Last post February 13, 2018, 02:14:51 pm
by CreateAForum
1 Replies
154 Views
Last post May 27, 2019, 02:30:33 pm
by CreateAForum