Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:45:41+00:00 2026-06-07T10:45:41+00:00

I’m starting in JS and have been having trouble with a particular function I’m

  • 0

I’m starting in JS and have been having trouble with a particular function I’m trying to write. The purpose is to have the text change once the button is pressed. The “nothing” text should change into “You say hi, I say Hey?” With the Hey? being text already on the document.

Here’s the code, any pointers would be welcome!

<html>
<head>
<title>Javascript test </title>
</head>

<body>

<p id="hey">Hey?</p>
<p id ="nothing">Nothing</p>
<INPUT type =button VALUE="Button?" OnClick=(take())>

<script>
function take(){
var hey=document.getElementById("hey");
var nothing =document.getElementById("one");

nothing.appendChild(document.createTextNode("You say hi, I say " + hey));
}
</script>
</body>
</html>

Alright, thanks for all the help guys. No one in particular was 100% right but i tried a combination of all the suggestions and got about 99% of the way to where i wanted to go. My code looks like this now. The last change im trying to make is not to append new text strings but to replace the old string with the string that is currently being appended.

<html>
<head>
<title>Javascript test </title>
</head>

<body>

<p id="hey">Hey?</p>
<p id ="nothing">Nothing</p>
<input type ="button" value="Button?" OnClick="take();"/>

<script>
function take(){
var hey=document.getElementById("hey");
var nothing =document.getElementById("nothing");

nothing.appendChild(document.createTextNode("You say hi, I say " + hey.innerHTML));

}

</script>
</body>
</html>

I appreciate the help, thank you Stack Overflow community!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:45:44+00:00Added an answer on June 7, 2026 at 10:45 am

    Your code has a few issues.

    First, you should specify type="text/javascript" on your script tag.

    Second, your input should look like this:

    <input id="button" type="button" value="Button?" />
    

    Third, you should bind your event handler in the script tag (See SoC):

    document.getElementById('button').onclick = take;
    

    Fourth, your function looks for an element with id one, which does not exist. Did you mean id nothing instead?

    Fifth, assuming you use the correct id to get the nothing element, you need to use the value from the other p when setting the value.

    var take = function () {
        var hey = document.getElementById('hey');
        var nothing = document.getElementById('nothing');
    
        nothing.innerHTML= 'You say hi, I say ' + hey.innerHTML;
    };
    

    See a working example here: http://jsfiddle.net/M5UWn/

    As a side note, I found jQFundamentals an excellent learning site for both jQuery and native javascript.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.