www.webdeveloper.com
Results 1 to 8 of 8

Thread: Hidden Text Displayed On Reload

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    15

    Hidden Text Displayed On Reload

    Hi Guys

    I have the following code on my site, which hides text, and then displays the text when a button is clicked:

    PHP Code:
    <html>
    <
    head>
    <
    script type="text/javascript"
    function 
    A_onclick(div) { 
     var 
    document.getElementById(div); 
     
    d.style.display = (d.style.display =="none")?'block':'none'
     return 
    false

    </script>
    </head>
    <body>
    <a href="#" onclick="return A_onclick('MyDiv');">
    <form><input type="button" class="button" value="Show Contact Details >>>"></form></a>

    <div id="MyDiv" style="display:none">
    Hidden text to be displayed when button is clicked
    </div>
    </body>
    </html> 
    What I'm looking for, is for the page to reload when the button is clicked, and the text to show when the page reloads.

    Any help would be appreciated.

  2. #2
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Without changing things around too much:

    HTML Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <script type="text/javascript">
    function A_onclick(div) {
    	var d = document.getElementById(div);
    	d.style.display = (d.style.display =="none")?'block':'none';
    	return false;
    }
    
    window.onload = function () {
    	if(document.location.search == "?refresh=true") A_onclick('MyDiv');
    }
    </script>
    </head>
    <body>
    
    <div>
    	<input type="button" class="button" value="Show Contact Details >>>" onclick="document.location=document.location.pathname+'?refresh=true'">
    </div>
    
    <div id="MyDiv" style="display:none">
    Hidden text to be displayed when button is clicked
    </div>
    
    </body>
    </html>
    54 68 65 42 65 61 72 4D 61 79

  3. #3
    Join Date
    Jul 2009
    Posts
    15
    You are an absolute STARR!!! Works perfectly.

    Will the "?refresh=true" in the url not pose problems with SEO?

  4. #4
    Join Date
    Jul 2009
    Posts
    15
    When the page reloads, is it possible for the form button to disappear?

  5. #5
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    Just give it an ID and set its display to none...
    54 68 65 42 65 61 72 4D 61 79

  6. #6
    Join Date
    Jul 2009
    Posts
    15
    PHP Code:
    Just give it an ID and set its display to none... 
    Please excuse my ignorance..... I'm new to these things. What would that look like? Here's the code I now have (your script):
    PHP Code:
    <head>
    <
    script type="text/javascript"
    function 
    A_onclick(div) { 
     var 
    document.getElementById(div); 
     
    d.style.display = (d.style.display =="none")?'block':'none'
     return 
    false
    }
    window.onload = function () {
        if(
    document.location.search == "?refresh=true"A_onclick('MyDiv');
    }
    </script>
    </head>

    <body>
    <div>
    <input type="button" class="button" value="Show Contact Details >>>" onclick="document.location=document.location.pathname+'?refresh=true'">
    </div>
    <div id="MyDiv" style="display:none">
    Text Text Text
    </div>
    </body> 

  7. #7
    Join Date
    Nov 2003
    Location
    Worthington, OH, USA
    Posts
    3,634
    PHP Code:
    <head>
    <
    script type="text/javascript">
    function 
    A_onclick(div) {
    var 
    document.getElementById(div);
    d.style.display = (d.style.display =="none")?'block':'none';
    return 
    false;
    }
    window.onload = function () {
        if(
    document.location.search == "?refresh=true") {
            
    A_onclick('MyDiv');
            
    A_onclick('hideBtn');
        }
    }
    </script>
    </head>

    <body>
    <div>
    <input type="button" class="button" value="Show Contact Details >>>" onclick="document.location=document.location.pathname+'?refresh=true'" id="hideBtn">
    </div>
    <div id="MyDiv" style="display:none">
    Text Text Text
    </div>
    </body> 
    54 68 65 42 65 61 72 4D 61 79

  8. #8
    Join Date
    Jul 2009
    Posts
    15
    I am eternally grateful to you. Your scripts works flawlessly. THANK YOU!
    Last edited by AlvinSA; 08-01-2009 at 04:45 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles