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 8912595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:14:30+00:00 2026-06-15T04:14:30+00:00

I am trying to create a text-based adventure game. I managed to figure out

  • 0

I am trying to create a text-based adventure game. I managed to figure out how to make text output in html’s textarea through simple onclick button, but now I am trying to do something new. I am having trouble with doing same thing but with input text where users can write anything in the box and then click on the button. Right now, I am trying to make this program to check the user input against some flag (in this case, I set my flag equal to ‘pizza’) before it does something. Unfortunately, my code doesn’t work at all. I think I don’t completely understand how the input is being passed around in JavaScript’s functions.

The JavaScript part:

function record(test) {
            var input = document.getElementById('filename');
            fileName = input.value;
            if (fileName == "pizza") {
            var obj=document.getElementById(test);
            obj.value="is this showing up in the textarea???"; 
            }
                        else {obj.value="wrong password!"; }
 
        }

The html part:

<input name="filename" id="filename" type="text">

<a id="record_button" onclick="record('textarea1');" href="javascript:void(0);" title="Record">Perform Action</a>

<textarea wrap="virtual" cols="73" rows="10" id="textarea1"></textarea>
  • 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-15T04:14:32+00:00Added an answer on June 15, 2026 at 4:14 am

    Add an event listener using JS:

    document.getElementById('record_button').onclick=function(){
        record('textarea1');
    }
    

    Also, there were a couple things wrong with your function. Here it is with corrections:

    function record(test) {
        var input = document.getElementById('filename');
        fileName = input.value;
        var obj = document.getElementById(test);
        if (fileName == "pizza") {
            obj.value = "is this showing up in the textarea???";
        }
        else {
            obj.value = "wrong password!";
        }
    
    }
    
    1. You were using document.getElementByID on the second line, which is incorrect capitalisation
    2. You were only defining obj conditionally, so the else clause always threw an exception.

    Here is a demonstration: http://jsfiddle.net/uQpp7/1/

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

Sidebar

Related Questions

My idea here is to create a text based adventure game. I'm trying to
I'm trying to create a very simple turn-based text RPG game. The code compiles
I am trying to create a text-based game in Java similar to Zork and
I'm trying to create a text-based game on the Windows phone. My thought is
I am trying to create a very simple (text based for now) email app
So, I'm trying to make a text based game in C++ Using Visual Studio
i am trying to create bulk folders based on simple text file. os.makedir helps
I trying to create an HTML/CSS/JavaScript based list manager. I'm using text input fields
I'm trying to create a text based Clojure game (inspired by Land of Lisp).
I'm trying to create text in html, that once clicked, the the value of

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.