www.webdeveloper.com
Results 1 to 2 of 2

Thread: NOT Sure: Need help with code...

  1. #1
    Join Date
    May 2011
    Posts
    1

    Exclamation NOT Sure: Need help with code...

    Hey, I am a beginner in JS and don't really understand it. I created this code for a text.
    Code:
    <script>
    function post()
    {
    var re = document.GetElementById("text");
    document.getElementById('submit').innerHTML="re";
    if (re == "" || re == "null"){
    alert("Type in a Text");
    return false;
    }
    else {
    return true;
    }
    }
    </script>
    <textarea id="text"></textarea>
    <button id="post" onclick="post()">Post</button>
    <blockquote id="submit"></blockquote>
    I am trying to copy the text written in the textarea box into bhe blockquote section when you click "POST" button in the section below:
    Code:
    document.getElementById('submit').innerHTML="re";
    I am also trying to place a false return when the textarea content has a null or no value in the code below:
    Code:
    if (re == "" || re == "null"){
    alert("Type in a Text");
    return false;
    }
    else {
    return true;
    }
    I need Help with these. I probabally gor the HTML incorrect or JS...

    Please and thank you.

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,350

    Lightbulb Something to try ...

    You had several syntax errors...note changes.
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> PostNote </title>
    <script type="text/javascript">
    function postNote() {
      var re = document.getElementById("text").value;
      document.getElementById('submit').innerHTML = re;
      if (re == "" || re == "null"){
        alert("Type in a Text");
        return false;
      } else {
        return true;
      }
    }
    </script>
    </head>
    <body>
    <textarea id="text"></textarea><br>
    <button id="postBtn" onclick="postNote()">Post</button>
    <button onclick="document.getElementById('text').value = ''">Clear</button>
    <blockquote id="submit"></blockquote>
    </body>
    </html>
    Use the error console in FF to help debug.

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