Jump to content

Javascript Read and Write

Geralt
Go to solution Solved by Nuluvius,

Haven't learnt JQuery tho so I gotta stick to JS.

 

Anyway, I managed to get it working by copying a sample code from one of my lessons. But I now have a problem, when a user submits the input the first time, it shows, but when the user inputs a second time, it erases the first input and writes the second input. How do I code it such that the second input shows below the first input and so on with the future inputs?

 

+=

Hi all, I can't seem to figure out for the life of me why I can't get my "fake" chat to work. I want to use Javascript to take input from a text box and output it in a read only text area and to append new submissions below the previous one afterwards. Can anyone help me?

 

Javascript:

 <script type="text/javascript">                function chat() {                    var chatinput = document.getElementByID('chatinput');                    var chat = document.getElementByID("chat");                    var output = chatinput.value;                    chat.value = "You have entered: " + output;                }            </script>
 

 

HTML:

 <fieldset>                <textarea rows="10" cols="90" name="chat" id="chat" placeholder="" readonly></textarea><br>                <input type="text" size="110" name="chatinput" id="chatinput" placeholder="Type a message">   <input type="button" value="Send" name="subButton" onclick="chat()"></fieldset>
Edited by alpenwasser
added code tags :)

~~~SnapDragon~~~

| CPU: AMD Ryzen 7 3700X @ PBO & -0.06v offset | CPU Cooler: Scythe Ninja 5 |RAM: 32GB G.Skill Flare X 3200MHz @ 3600MHz 1.45V| Mobo: Gigabyte X570 Aorus Elite  | Storage: Crucial MX300 500GB + Western Digital Blue M.2 250GB + Seagate Barracuda 2TB + Western Digital 1TB Blue | Graphics Card: Asus ROG Strix RTX 2070 Super Advanced 8G | Case: Cooler Master HAF X | PSU: Superflower Leadex Silver 650W |

 

Link to comment
Share on other sites

Link to post
Share on other sites

onlick="chat()"> typo?

Asrock 890GX Extreme 3 - AMD Phenom II X4 955 @3.50GHz - Arctic Cooling Freezer XTREME Rev.2 - 4GB Kingston HyperX - AMD Radeon HD7850 - Kingston V300 240GB - Samsung Spinpoint F3 1TB - Chieftec APS-750 - Cooler Master HAF912 PLUS


osu! profile

Link to comment
Share on other sites

Link to post
Share on other sites

onlick="chat()"> typo?

 

Doesn't make a difference if I correct it. It still doesn't append the input into the textarea.

~~~SnapDragon~~~

| CPU: AMD Ryzen 7 3700X @ PBO & -0.06v offset | CPU Cooler: Scythe Ninja 5 |RAM: 32GB G.Skill Flare X 3200MHz @ 3600MHz 1.45V| Mobo: Gigabyte X570 Aorus Elite  | Storage: Crucial MX300 500GB + Western Digital Blue M.2 250GB + Seagate Barracuda 2TB + Western Digital 1TB Blue | Graphics Card: Asus ROG Strix RTX 2070 Super Advanced 8G | Case: Cooler Master HAF X | PSU: Superflower Leadex Silver 650W |

 

Link to comment
Share on other sites

Link to post
Share on other sites

I use JQuery more often than simple JS.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

I use JQuery more often than simple JS.

 

Haven't learnt JQuery tho so I gotta stick to JS.

 

Anyway, I managed to get it working by copying a sample code from one of my lessons. But I now have a problem, when a user submits the input the first time, it shows, but when the user inputs a second time, it erases the first input and writes the second input. How do I code it such that the second input shows below the first input and so on with the future inputs?

~~~SnapDragon~~~

| CPU: AMD Ryzen 7 3700X @ PBO & -0.06v offset | CPU Cooler: Scythe Ninja 5 |RAM: 32GB G.Skill Flare X 3200MHz @ 3600MHz 1.45V| Mobo: Gigabyte X570 Aorus Elite  | Storage: Crucial MX300 500GB + Western Digital Blue M.2 250GB + Seagate Barracuda 2TB + Western Digital 1TB Blue | Graphics Card: Asus ROG Strix RTX 2070 Super Advanced 8G | Case: Cooler Master HAF X | PSU: Superflower Leadex Silver 650W |

 

Link to comment
Share on other sites

Link to post
Share on other sites

Haven't learnt JQuery tho so I gotta stick to JS.

 

Anyway, I managed to get it working by copying a sample code from one of my lessons. But I now have a problem, when a user submits the input the first time, it shows, but when the user inputs a second time, it erases the first input and writes the second input. How do I code it such that the second input shows below the first input and so on with the future inputs?

 

+=

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

+=

 

THANK YOU!

 

My god, I've been trying to solve this for hours already!

~~~SnapDragon~~~

| CPU: AMD Ryzen 7 3700X @ PBO & -0.06v offset | CPU Cooler: Scythe Ninja 5 |RAM: 32GB G.Skill Flare X 3200MHz @ 3600MHz 1.45V| Mobo: Gigabyte X570 Aorus Elite  | Storage: Crucial MX300 500GB + Western Digital Blue M.2 250GB + Seagate Barracuda 2TB + Western Digital 1TB Blue | Graphics Card: Asus ROG Strix RTX 2070 Super Advanced 8G | Case: Cooler Master HAF X | PSU: Superflower Leadex Silver 650W |

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×