Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts

    Creating lists, variable list items

    I'm having problems trying to think of ways to do this. What I've got is a drop down menu

    Code:
    <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>
    	</select>
    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.

    Code:
    function lists(type){
    		for(i=1;i<i++;i++){
    			var li = prompt('Insert list item');
    			if(li == null){
    				break;
    			}
    		}
    		document.form1.content.value += '<'+type+'><li>'+li+'</li></'+type+'>';
    	}

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,042
    Thanks
    0
    Thanked 251 Times in 247 Posts
    Try this:
    Code:
     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+'>';
        }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •