www.webdeveloper.com
Results 1 to 3 of 3

Thread: How would I post this to the page?

  1. #1
    Join Date
    Aug 2014
    Posts
    1

    How would I post this to the page?

    Hello, I'm new to JavaScript and I was wondering how I'd post what I wrote in my TextBox onto the HTML page. I got it to print out into the console, but not to the page. I also plan on making it save. This is my current Script:



    <script>
    var postBlog = document.getElementById("postBlog")
    postBlog.onclick = function(){
    console.log("Someone wants to post a blogpost")
    console.log(document.getElementById("Texto").value)

    }
    </script>

  2. #2
    Join Date
    Aug 2014
    Posts
    2
    Here is the simplest possible thing you could do.
    Say you have an HTML element <div id="blog"> where you would like to post the content from TextBox.
    Just add the last line to your script:

    Code:
    <script>
    var postBlog = document.getElementById("postBlog");
    postBlog.onclick = function(){
    
    console.log("Someone wants to post a blogpost"); console.log(document.getElementById("Texto").value); document.getElementById("blog").textContent = document.getElementById("Texto").value;
    }; </script>
    There you have it.
    And as for saving it, you can't really do that permanently with only javascript. You could save it for the current user (and the current browser in use) using localstorage but that isn't really persistent.

  3. #3
    I completely agree with you "aloyzije" great information.

Thread Information

Users Browsing this Thread

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

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