View Full Version : Creating lists, variable list items

01-26-2005, 01:37 AM
I'm having problems trying to think of ways to do this. What I've got is a drop down menu

<select name="list" onChange='javascript:lists(this.options[this.selectedIndex].value)'>
<option value="" selected">Lists</option>
<option value="ol">Ordered list</option>
<option value="ul">Unordered list</option>

Which I want to trigger the lists function, to bring up a js prompt for them to fill in with the various list items they want in the selected list. I'm stuck on the loop part, have no idea how to make the prompt loop until the user hits cancel, which will mean they have no more items to add to the list.

function lists(type){
var li = prompt('Insert list item');
if(li == null){
document.form1.content.value += '<'+type+'><li>'+li+'</li></'+type+'>';

01-26-2005, 02:50 AM
Try this:

function lists(type){
var li;
var list = '';
do {
li = prompt('Insert list item','');
if (li) list += '<li>'+li+'</li>';
while (li)
document.form1.content.value += '<'+type+'>'+list+'</'+type+'>';