Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Very Quick Java Help

  1. #1
    Join Date
    Apr 2008
    Beans
    332

    Very Quick Java Help

    Hello I'm fairly new to java but I am learning quick.

    I am working on a website that uses .tpl files mainly to control content on pages.

    Currently I am running this:

    Code:
    <a href="#"
    onclick="document.getElementById('text1').style.display='block';">Question numero uno</a>
    <div id="text1" style="display:none;">
    This text is revealed by button 1 and hidden by button 3.
    <a href="#"
    onclick="document.getElementById('text1').style.display = 'none';">
    hide</div></a>
    The question is clicked, the answer shows, and they have the option to hide it again.

    I would much rather have the person click the question again to hide the answer and not have to click "hide"

    Since I am dealing in .tpl files this code i found doesn't work at all
    Code:
    <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>
    And the usage would be
    Code:
    <a href="#" onclick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>
    <div id="foo">This is foo</div>
    I believe it would work if I could use a single line. Without having to establish variables.

    I was thinking
    Code:
    if{document.getElementById('text1').style.display='block' onclick="document.getElementById('text1').style.display='none'}
    else onclick="document.getElementById('text1').style.display='block'}
    but i can't figure out the proper usage.
    I have a strong hatred of KDE

  2. #2
    Join Date
    Nov 2009
    Beans
    34

    Re: Very Quick Java Help

    PHP Code:
    function toggleMe() {
        if (
    document.getElementById('text1').style.display == 'block') { 
            
    document.getElementById('text1').style.display 'none';
        } else {
            
    document.getElementById('text1').style.display 'block';
        }

    PHP Code:
    <a href="#" onClick="toggleMe()">Question</a>
    <
    div id="text1">Answer</div
    Last edited by MonoDeem; November 16th, 2009 at 11:37 PM. Reason: P.S. - Java isn't the same as JavaScript ..

  3. #3
    Join Date
    Nov 2006
    Location
    Philadelphia, PA
    Beans
    Hidden!

    Re: Very Quick Java Help

    Code:
    java != javascript && "Javascript".contains("Java");
    True statement.
    Last edited by kavon89; November 16th, 2009 at 11:46 PM.
    ThinkPad R61 14" | Fedora 14 | Core 2 Duo 2.0Ghz | 4GB DDR2 | 64GB SSD

  4. #4
    Join Date
    Nov 2009
    Beans
    34

    Re: Very Quick Java Help

    Quote Originally Posted by kavon89 View Post
    Code:
    (java != javascript && "Javascript".contains("Java")) == true
    Code:
    Error [1]: Undefined variable: java
    Error [1]: Undefined variable: javascript

  5. #5
    Join Date
    Nov 2006
    Location
    Philadelphia, PA
    Beans
    Hidden!

    Re: Very Quick Java Help

    Quote Originally Posted by MonoDeem View Post
    Code:
    Error [1]: Undefined variable: java
    Error [1]: Undefined variable: javascript
    Although I updated it, you're right it has errors.

    Code:
    !(Javascript instanceof Java) && "Javascript".contains("Java");
    I'm not too sure if I used instanceof correctly if Javascript and Java were defined classes though.
    ThinkPad R61 14" | Fedora 14 | Core 2 Duo 2.0Ghz | 4GB DDR2 | 64GB SSD

  6. #6
    Join Date
    Apr 2008
    Beans
    332

    Re: Very Quick Java Help

    Quote Originally Posted by MonoDeem View Post
    PHP Code:
    function toggleMe() {
        if (
    document.getElementById('text1').style.display == 'block') { 
            
    document.getElementById('text1').style.display 'none';
        } else {
            
    document.getElementById('text1').style.display 'block';
        }

    PHP Code:
    <a href="#" onClick="toggleMe()">Question</a>
    <
    div id="text1">Answer</div

    I tried putting this into the .tpl that I work with. It caused the page to be completely blank. Is there a different way I can do this, or is there a special way I have to implement this code? I've tried wrapping the function in <?php ?> but to no avail.
    I have a strong hatred of KDE

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Beans
    2,185
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Very Quick Java Help

    Ubuntu 12.04

  8. #8
    Join Date
    Nov 2007
    Location
    London, England
    Beans
    7,701

    Re: Very Quick Java Help

    This works for me:
    Code:
    <html>
    <script type="text/javascript">
    <!--
        function toggle_visibility(id) {
           var e = document.getElementById(id);
           if(e.style.display == 'none')
              e.style.display = 'block';
           else
              e.style.display = 'none';
        }
    //-->
    </script>
    <a href="#" onclick="toggle_visibility('foo');">Click here to toggle visibility of element #foo</a>
    <div id="foo" style="display:none">This is foo</div>
    </html>

  9. #9
    Join Date
    Dec 2007
    Location
    UK
    Beans
    571
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Very Quick Java Help

    document.getElementById('text1').style.display == 'block')
    For some reason IE craps out sometimes with code like this. To hide IEs crappyness its best to do it the way The Cog did - getting the element as a variable first before doing things with it. Personally I like using JQuery for this kind of stuff as you can add transition effects very easily. It also handles many of IE's issues, so I don't have to worry about them

  10. #10
    Join Date
    Apr 2008
    Beans
    332

    Re: Very Quick Java Help

    Quote Originally Posted by jespdj View Post
    Lolol sorry java /= javascript. I am a huge noob to scripting.

    But I'm still getting the issue, and I think that it is just the tools I have to work with.

    I have no doubt that the code would work in a normal situation but I think I have a different situation. I don't work with physical .tpl files, everything is online. It's a web based interface that

    The problem is, when I try and insert any type of setup that establishes variables I get a completely blank page. Is there anyway to write this as {if blank is true}onclick this..{else}onclick that.
    I have a strong hatred of KDE

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •