unordered list editor javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    unordered list editor javascript

    why when i try to make the string(unordere d list) to be in a div it apears beside the div
    Code:
     function makeUnorderedList(txt){
     var tempText="";	
     var splitResult = txt.split('\n');
     var offer=document.getElementById("editor_displaying_text").innerHTML;
     offer=offer.replace(txt,"");
    
     
     for(i = 0; i < splitResult.length; i++){
    	tempText=splitResult[i];
    	tempText=tempText.replace(splitResult[i],'<li>'+splitResult[i]+'</li>');
    	offer+=tempText;	
    }
    offer=offer.replace(tempText,'<ul>'+tempText+'</ul>');
    document.getElementById("editor_displaying_text").innerHTML = offer;
    }
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    tempText is the last split item on line 13. You need to replace the whole text (txt) in offer. Remove line 5 and make the replacement on line 13.

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      hmm i did that but still get the unordered ,list underneath the div and the content of the div doesn't change
      Thank You

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        What does the updated code look like?

        Comment

        • oll3i
          Contributor
          • Mar 2007
          • 679

          #5
          Code:
           function makeUnorderedList(txt){
           var tempText="";
           var textToRemove="";	
           var splitResult = txt.split('\n');
           var offer=document.getElementById("editor_displaying_text").innerHTML;
           
          
           
           for(i = 0; i < splitResult.length; i++){
          	tempText=splitResult[i];
          	tempText=tempText.replace(splitResult[i],'<li>'+splitResult[i]+'</li>');
          	textToRemove+=tempText;
          	offer+=tempText;	
          }
          offer=offer.replace(textToRemove,'<ul>'+textToRemove+'</ul>');
          document.getElementById("editor_displaying_text").innerHTML = offer;
          }
          it only makes unordered list on selected text but it doesn't display it in a div
          thank You

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Try alerting txtToRemove, offer and tempText to see if they match for the replace to work.

            Comment

            Working...