JavaScript not executing text-box value in HTML

arthrax

I am new to JavaScript in HTML and was given the project to write a Mad Lib form using JS. I coded it and reviewed it many times, but I couldn't find the problem with the code: the program is not changing the text box value in the HTML document. Can you please help? Code:

function madLib() {
  var name, object, objectTwo, adjective, adverb, verb, place, mood, buildingStructure;
  name = document.MadLibForm.name.value;
  object = document.MadLibForm.object.value;
  objectTwo = document.MadLibForm.objectwo.value;
  adjective = document.MadLibForm.adjective.value;
  adverb = document.MadLibForm.adverb.value;
  verb = document.MadLibForm.verb.value;
  place = document.MadLibForm.place.value;
  mood = document.MadLibForm.mood.value;

  buildingStructure = name + " went to PLACE after a long time. " + name + " loved " + place + " because it was his/her favorite place when she was a kid. " + name + " took the " + adjective + " " + obeject + " with him to the " + place + ", which he/she used to it " + adverb + verb + ". He/She also took " + objectTwo + " with him/her, but did not use it at all during the visit. Still, at the end of the visit, he/she was very " + mood + " .";

  document.MadLibForm.displayFullMadLib.value = buildingStructure;
}
<!DOCTYPE html>

<head>
  <title>Mad Libs</title>
  <meta charset="utf-8">
  <link rel="stylesheet" href="styles.css" type="text/css">
  <script>
    function madLib() {
      var name, object, objectTwo, adjective, adverb, verb, place, mood, buildingStructure;
      name = document.MadLibForm.name.value;
      object = document.MadLibForm.object.value;
      objectTwo = document.MadLibForm.objectwo.value;
      adjective = document.MadLibForm.adjective.value;
      adverb = document.MadLibForm.adverb.value;
      verb = document.MadLibForm.verb.value;
      place = document.MadLibForm.place.value;
      mood = document.MadLibForm.mood.value;

      buildingStructure = name + " went to PLACE after a long time. " + name + " loved " + place + " because it was his/her favorite place when she was a kid. " + name + " took the " + adjective + " " + obeject + " with him to the " + place + ", which he/she used to it " + adverb + verb + ". He/She also took " + objectTwo + " with him/her, but did not use it at all during the visit. Still, at the end of the visit, he/she was very " + mood + " .";

      document.MadLibForm.displayFullMadLib.value = buildingStructure;
    }
  </script>
</head>

<body>
  <div id="main">
    <form name="MadLibForm">
      <table>
        <tr>
          <th colspan="2">wEiRd Mad Lib</th>
        </tr>
        <tr>
          <td>Your Name</td>
          <td>
            <input type="text" name="name" class="inputs">
          </td>
        </tr>
        <tr>
          <td>Object</td>
          <td>
            <input type="text" name="object" class="inputs">
          </td>
        </tr>
        <tr>
          <td>Another Object</td>
          <td>
            <input type="text" name="objecttwo" class="inputs">
          </td>
        </tr>
        <tr>
          <td>Place</td>
          <td>
            <input type="text" name="place" class="inputs">
          </td>
        </tr>
        <tr>
          <td>Verb</td>
          <td>
            <input type="text" name="verb" class="inputs">
          </td>
        </tr>
        <tr>
          <td>Adjective</td>
          <td>
            <input type="text" name="adjective" class="inputs">
          </td>
        </tr>
        <tr>
          <td>Adverb</td>
          <td>
            <input type="text" name="adverb" class="inputs">
          </td>
        </tr>
        <tr>
          <td>Mood</td>
          <td>
            <input type="text" name="mood" class="inputs">
          </td>
        </tr>
        <tr>
          <td>
            <div>
              <input type="button" onClick="madLib()" value="Get Your Story!" id="button">
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="2">&nbsp;
            <textarea name="displayFullMadLib" rows="9" cols="65"></textarea>
          </td>
        </tr>
      </table>
    </form>
  </div>
  <!--main-->
</body>

</html>

Thank you so much :)

Zakaria Acharki

Your updated fiddle working fine after two changes.

  1. Change :

    objectTwo = document.MadLibForm.objectwo.value;
    

    To :

    objectTwo = document.MadLibForm.objecttwo.value; //two `t`
    
  2. Replace obeject by object in :

    ..." took the " + adjective + " " + object + " with him to the " + place ...+ 
    

JS :

madLib = function() {
      var name, object, objectTwo, adjective, adverb, verb, place, mood, buildingStructure;
      name = document.MadLibForm.name.value;
      object = document.MadLibForm.object.value;
      objectTwo = document.MadLibForm.objecttwo.value;
      adjective = document.MadLibForm.adjective.value;
      adverb = document.MadLibForm.adverb.value;
      verb = document.MadLibForm.verb.value;
      place = document.MadLibForm.place.value;
      mood = document.MadLibForm.mood.value;

      buildingStructure = name + " went to PLACE after a long time. " + name + " loved " + place + " because it was his/her favorite place when she was a kid. " + name + " took the " + adjective + " " + object + " with him to the " + place + ", which he/she used to it " + adverb + verb + ". He/She also took " + objectTwo + " with him/her, but did not use it at all during the visit. Still, at the end of the visit, he/she was very " + mood + " .";

      document.MadLibForm.displayFullMadLib.value = buildingStructure;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Enter the value in text box with JavaScript in HTML

From Dev

Enter the value in text box with JavaScript in HTML

From Dev

Returning a value to a text box with JavaScript

From Dev

Value will blink only once at the html text box

From Dev

Unable to display value in HTML text input box

From Dev

Comment Box add text value without html

From Dev

Value will blink only once at the html text box

From Dev

Javascript on button click add value to text box

From Dev

Javascript value not working with input text box

From Dev

Javascript Hide-Unhide HTML Text Box

From Dev

How to Create A Suggestion Box (Prompt Box in Javascript) Inside a Html Box With Text

From Dev

In the html text box, how to show value which itself contains "" symbol?

From Dev

How to populate the value of a Text Box based on the value in a Combo Box in a html page

From Dev

how to get runtime value of one text box and show it to other text box using javascript

From Dev

how to set text box value to upload filename using javascript?

From Dev

How to enable text box on drop down value change in javascript

From Dev

Display the value of button in the text box and change the color of the selected button in javascript

From Dev

Can't set text box value inside javascript sliding div

From Dev

how to set text box value to upload filename using javascript?

From Dev

how to send value to servlet from javascript (Dynamically creates text box)

From Dev

How to enable text box on drop down value change in javascript

From Dev

HTML input box readonly---javascript button overrides text

From Dev

How to edit HTML Form text box using Javascript?

From Dev

How to make automatic line numbers next to an html text box with javascript?

From Dev

How to edit HTML Form text box using Javascript?

From Dev

Calling up html text box using javascript and converting it to an integer

From Dev

Calculate data based on text box values with javascript/html

From Dev

Javascript refresh time in HTML text box; getElementByID error

From Dev

Pass Search value from one html page text box to another html page text box on click using cookies?

Related Related

  1. 1

    Enter the value in text box with JavaScript in HTML

  2. 2

    Enter the value in text box with JavaScript in HTML

  3. 3

    Returning a value to a text box with JavaScript

  4. 4

    Value will blink only once at the html text box

  5. 5

    Unable to display value in HTML text input box

  6. 6

    Comment Box add text value without html

  7. 7

    Value will blink only once at the html text box

  8. 8

    Javascript on button click add value to text box

  9. 9

    Javascript value not working with input text box

  10. 10

    Javascript Hide-Unhide HTML Text Box

  11. 11

    How to Create A Suggestion Box (Prompt Box in Javascript) Inside a Html Box With Text

  12. 12

    In the html text box, how to show value which itself contains "" symbol?

  13. 13

    How to populate the value of a Text Box based on the value in a Combo Box in a html page

  14. 14

    how to get runtime value of one text box and show it to other text box using javascript

  15. 15

    how to set text box value to upload filename using javascript?

  16. 16

    How to enable text box on drop down value change in javascript

  17. 17

    Display the value of button in the text box and change the color of the selected button in javascript

  18. 18

    Can't set text box value inside javascript sliding div

  19. 19

    how to set text box value to upload filename using javascript?

  20. 20

    how to send value to servlet from javascript (Dynamically creates text box)

  21. 21

    How to enable text box on drop down value change in javascript

  22. 22

    HTML input box readonly---javascript button overrides text

  23. 23

    How to edit HTML Form text box using Javascript?

  24. 24

    How to make automatic line numbers next to an html text box with javascript?

  25. 25

    How to edit HTML Form text box using Javascript?

  26. 26

    Calling up html text box using javascript and converting it to an integer

  27. 27

    Calculate data based on text box values with javascript/html

  28. 28

    Javascript refresh time in HTML text box; getElementByID error

  29. 29

    Pass Search value from one html page text box to another html page text box on click using cookies?

HotTag

Archive