none
create a text box RRS feed

  • Question

  • I would like to create a text box, in HTML. Whenever I enter data, I press the Save button and the text automatically becomes combobox in this form. Whenever I close the page, the data remains there, recorded. Another button clears the selected data in a combo box. As I create, all this code, what will do it?
    • Edited by Vitor Patrício Sunday, February 19, 2017 11:24 PM Formato text
    Sunday, February 19, 2017 10:50 PM

Answers

  • <!DOCTYPE html>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <meta charset="utf-8" />
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script type="text/javascript" src="jquery-3.1.1.min.js"></script>
        <script type="text/javascript">
        function AddValue() {

        var valueToAdd = $( "#Textbox" ).val();

            $( "#Listbox" ).append( '<option value="' + valueToAdd + '">' + valueToAdd + '</option>' );
        }

        function RemoveValue() {

        var valueToRemove = $( "#Textbox" ).val();

            $( "#Listbox option[value='" + valueToRemove + "']" ).remove();
        }
        </script>
    </head>
    <body>

    <input id="Textbox" type="text" />
    <br />
    <input id="Add" type="button" value="Hinzufügen" onclick="AddValue();" />
    <input id="Remove" type="button" value="Entfernen" onclick="RemoveValue();" />

    <br /><br />

    <select id="Listbox" size="1" style="width: 200px;">
        <option value="">--bitte auswählen--</option>
        <option value="Abc">Abc</option>
        <option value="Def">Def</option>
    </select>

    </body>
    </html>
    Friday, March 3, 2017 10:56 PM