 <p>You can add a click handler to each link in the <code>#ullist</code> element then set teh value of the text box</p> <pre><code>var text = document.getElementById('textbox'); var anchor = document.querySelector('#button'); var links = document.querySelectorAll('#ullist a'); for(var i = 0;i&lt; links.length;i++){ links[i].onclick = function(){ text.value = this.textContent || this.innerText } } </code></pre> <p>Demo: <a href="https://jsfiddle.net/arunpjohny/L2ogujk0/" rel="nofollow">Fiddle</a></p> <hr> <p>Using jQuery</p> <pre><code>jQuery(function($){ var $text = $('#textbox'); $('#ullist a').click(function () { $text.val($(this).text()); }); $('#button').click(function (e) { var textbox_text = $text.val(); var textbox_file = new Blob([textbox_text], { "type": "application/bat" }); this.href = URL.createObjectURL(textbox_file); this.download = "servicename.txt"; }); $('#list').click(function (e) { $('#ullist').toggle(); }); }) </code></pre> <p>Demo: <a href="https://jsfiddle.net/arunpjohny/L2ogujk0/2/" rel="nofollow">Fiddle</a></p>