Advanced Search

Results 1 to 9 of 9

Thread: Way to clear the screen when function call?

  1. #1
    Join Date
    Oct 2013
    Location
    Finland
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Way to clear the screen when function call?

    So yeah i need help with that code is here

    Code:
    <script>
    function myInventory()
    {
    document.write('<pre>');
    document.writeln("A warm blanket");
    document.writeln('<button onClick="newWorld()">Back</button>');
    }
    function newWorld()
    {
    document.write('<pre>');
    document.writeln("Hello and welcome to World of My Core!");
    document.writeln("What would you like to do?");
      {
      document.writeln('<button onClick="myInventory()">Inventory</button>');
      }
    }
    </script>
    So i want it to clear the screen when i call the function myInventory() and newWorld() with the Back button

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    261
    Thanked 690 Times in 678 Posts

    Default

    Why are you using document.write? Wouldn't it just be easier to modify an existing element and changing the innerHTML to something new (or no content)? If you want it to be the whole page, then you can create a wrapper <div> that contains everything, or try modifying <body> directly (although I'm not positive that would always work-- there could be security restrictions or browser limitations-- at least I expect there would be at a higher level like the <html> tag).
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Oct 2013
    Location
    Finland
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Okay listen im just a beginner at html5 coding.

    But would it really be easier like i don't know how to use <div> like at all
    Last edited by NitroDev; 10-19-2013 at 09:15 AM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,154
    Thanks
    261
    Thanked 690 Times in 678 Posts

    Default

    You should just do some trial and error then and see where it goes.

    document.write isn't as useful as it might seem.

    You can create a div surrounding the content on your page like this:
    Code:
    <html>
    ...
    <body>
    <div id="mydiv">
    ... [all of the rest of your page goes here]...
    </div>
    </body>
    </html>
    Then you can do something along these lines:
    document.getElementById('mydiv').innerHTML = '';
    (Set the innerHTML of that div to nothing.)
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Oct 2013
    Location
    Finland
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    So like this?

    Code:
    <html>
    <body>
    <div id="MenuMech>
    function myInventory()
    {
    document.write('<pre>');
    document.writeln("A warm blanket");
    document.writeln('<button onClick="newWorld()">Back</button>');
    }
    function newWorld()
    {
    document.write('<pre>');
    document.writeln("Hello and welcome to World of My Core!");
    document.writeln("What would you like to do?");
      {
      document.writeln('<button onClick="myInventory()">Inventory</button>');
      }
    }
    </div>
    </body>
    </html>

  6. #6
    Join Date
    Oct 2013
    Location
    Finland
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by NitroDev View Post
    So like this?

    Code:
    <html>
    <body>
    <div id="MenuMech>
    function myInventory()
    {
    document.write('<pre>');
    document.writeln("A warm blanket");
    document.writeln('<button onClick="newWorld()">Back</button>');
    }
    function newWorld()
    {
    document.write('<pre>');
    document.writeln("Hello and welcome to World of My Core!");
    document.writeln("What would you like to do?");
      {
      document.writeln('<button onClick="myInventory()">Inventory</button>');
      }
    }
    </div>
    </body>
    </html>
    Or the intire page?

  7. #7
    Join Date
    Oct 2013
    Location
    Finland
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    I need more info

  8. #8
    Join Date
    Oct 2013
    Location
    Finland
    Posts
    52
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Question Function help

    I want to get the page cleared after button click to call function

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    <script>
    <div id="Start">
    function myInventory()
    {
    document.write('<pre>');
    document.writeln("A warm blanket");
    document.writeln('<button onClick="newWorld()">Back</button>');
    }
    function newWorld()
    {
    document.write('<pre>');
    document.writeln("Hello and welcome to World of My Core!");
    document.writeln("What would you like to do?");
      {
      document.writeln('<button onClick="myInventory()">Inventory</button>');
      }
    }
    document.getElementById('Start').innerHTML ="";
    </script>
    
    <h1>Welcome to My Core</h1>
    <p>Start by choosing your name</p>
    
    <form action="">
    Username: <input type=" text" name="Username"><br>
    </form>
    <p>Then choose your gender</p>
    
    <form>
    <input type="radio" name="gender" value="Male">Male<br>
    <input type="radio" name="gender" value="Female">Female
    </form>
    
    <p>Press the Play button to play!<p>
    
    <button onClick="newWorld()">Play</button>
    </body>
    </div>
    </html>
    Theres the code so i want it to clear the screen when i call functions myInventory() and newWorld() by pressing the Inventory and Back buttons

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,687
    Thanks
    43
    Thanked 3,129 Times in 3,095 Posts
    Blog Entries
    12

    Default

    Moderator's Note:

    I've merged these two similar threads for now.

    In the future, please do not open more than one thread for the same topic, simply continue the thread you've already opened.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. The Following User Says Thank You to jscheuer1 For This Useful Post:

    NitroDev (10-19-2013)

Similar Threads

  1. Function with URL call
    By dz.slick in forum JavaScript
    Replies: 14
    Last Post: 11-11-2011, 09:20 AM
  2. Interstitial Function Call
    By ACLLC in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-25-2010, 08:40 PM
  3. Called from accordion menu don't clear screen
    By kiernan7 in forum Dynamic Drive scripts help
    Replies: 3
    Last Post: 03-13-2009, 06:54 PM
  4. call second function after first
    By vineet in forum JavaScript
    Replies: 2
    Last Post: 12-31-2008, 02:59 PM
  5. Replies: 2
    Last Post: 08-02-2007, 06:19 AM

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
  •