Jump to content

Javascript Read and Write

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 9 9950X3D | CPU Cooler: Gigabyte Aorus Waterforce X II 360mm |RAM: 2x32GB G.Skill Trident Z5 Neo RGB 6000MHz | Mobo: Gigabyte X870E Aorus Xtreme X3D AI Top  | Storage: Samsung 9100 Pro 4TB + Samsung 990 Pro 4TB + Samsung 870 Evo 4TB + Samsung 870 Evo 2TB | Graphics Card: Gigabyte RTX 5090 Aorus Master 32G | Case: Lian Li Lancool 216 | PSU: Seasonic Vertex GX-1200 |

 

Link to comment
https://linustechtips.com/topic/395634-javascript-read-and-write/
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 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 9 9950X3D | CPU Cooler: Gigabyte Aorus Waterforce X II 360mm |RAM: 2x32GB G.Skill Trident Z5 Neo RGB 6000MHz | Mobo: Gigabyte X870E Aorus Xtreme X3D AI Top  | Storage: Samsung 9100 Pro 4TB + Samsung 990 Pro 4TB + Samsung 870 Evo 4TB + Samsung 870 Evo 2TB | Graphics Card: Gigabyte RTX 5090 Aorus Master 32G | Case: Lian Li Lancool 216 | PSU: Seasonic Vertex GX-1200 |

 

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 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 9 9950X3D | CPU Cooler: Gigabyte Aorus Waterforce X II 360mm |RAM: 2x32GB G.Skill Trident Z5 Neo RGB 6000MHz | Mobo: Gigabyte X870E Aorus Xtreme X3D AI Top  | Storage: Samsung 9100 Pro 4TB + Samsung 990 Pro 4TB + Samsung 870 Evo 4TB + Samsung 870 Evo 2TB | Graphics Card: Gigabyte RTX 5090 Aorus Master 32G | Case: Lian Li Lancool 216 | PSU: Seasonic Vertex GX-1200 |

 

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 post
Share on other sites

+=

 

THANK YOU!

 

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

~~~SnapDragon~~~

| CPU: AMD Ryzen 9 9950X3D | CPU Cooler: Gigabyte Aorus Waterforce X II 360mm |RAM: 2x32GB G.Skill Trident Z5 Neo RGB 6000MHz | Mobo: Gigabyte X870E Aorus Xtreme X3D AI Top  | Storage: Samsung 9100 Pro 4TB + Samsung 990 Pro 4TB + Samsung 870 Evo 4TB + Samsung 870 Evo 2TB | Graphics Card: Gigabyte RTX 5090 Aorus Master 32G | Case: Lian Li Lancool 216 | PSU: Seasonic Vertex GX-1200 |

 

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

×