Please look at this demo: http://www.freewebs.com/moreauctions/addtobox.html As you can see this script adds linebreak after each entry. What I would like to do is have another button to undo each entry. So let's say the content of the textarea is: Entry one linebreak Entry two linebreak__________stops here Entry three linebreak We want the value of text area to always end with a linebreak so onclick it would get the value of textarea, start at the end and delete the last linebreak and any text before it, stopping at the next linebreak.
What about adding an extra dropdown box? For each entry added, it is also added as an item in the dropdown box. Then, people might select an item in the dropdown box and click 'Delete' button. The value of the textarea will then be re-drawn, simply by using the values of the dropdown box. Useful resources: Add an Item to a DropDown box. <script type=â€text/javascriptâ€> function AddItem(Text,Value) { // Create an Option object var opt = document.createElement(“optionâ€); // Add an Option object to Drop Down/List Box Make the dropdown box DropDownList as ID. document.getElementById(“DropDownListâ€).options.add(opt); // Assign text and value to Option object opt.text = Text; opt.value = Value; }<script /> Code (markup): Removing an item from dropdown list. // where DropDownList is the ID and count is the option ID. Note that you might get that ID with using a for loop (see further) DropDownList.remove (count); Code (markup): Getting all items from a dropdown list. var count; for (count = 0 ; count < DropDownList.options.length ; count++){ // This code prints the value of each item of the dropdown list. You may modify the code to match your purposes. print DropDownList.options[count].value + "<br>"; } Code (markup): Hope this helps you a bit.
That is a great idea. But I'm a noob to JS so do I put all of your code in the same <script></script>? I'm a bit confused. Could you encorporate this into my code? <input size="20" id="inputtext"> <input name="add" value="Add" onclick="if(document.getElementById('inputtext').value != 0) document.getElementById('textarea').value+='• '+inputtext.value+'\n\n'; document.getElementById('inputtext').value='';" type="button"> <textarea rows="15" id="textarea" name="box" cols="22" disabled></textarea> Code (markup):