locked
Set default text to Rich Text Box by using Jquery in SharePoint List? RRS feed

  • Question

  • Hi,

    I have a requirement like Rich text box having some default text based on Radio Button selection.

    

    If I am selecting second option(FAQ Template) then Rich Text Box content will update with some other content.

    My Code is:

    $(document).ready(function() { 
        var textContent1='<div><b>Summary</b></div>'
        				+'<hr color="black">'    				
        				+'<div id="Summary-Instruction">Instructions:</div></br></br>'
        				+'<div><b>Additional Comments</b></div>'
        				+'<hr color="black">'    				
        				+'<div>Instructions:</div></br></br>'; 
        				
       var textContent2='<div><b>Questions</b></div>'
        				+'<hr color="black">'    				
        				+'<div id="Summary-Instruction">Instructions:State the question.</div></br></br>'
        				+'<div><b>Answer</b></div>'
        				+'<hr color="black">'    				
        				+'<div id="Summary-Instruction">Instructions:Provide the answer(s) to the question.</div></br></br>'
        				+'<div><b>Additional Comments</b></div>'
        				+'<hr color="black">'    				
        				+'<div>Instructions:Provide any additional information that will help readers with their questions.</div></br></br>'; 
     
      $('textarea[title="SummaryDetails"]').val(textContent1);
    
      $('input[type="radio"]').click(function(){
        
        if($(this).val()=="option1")
        {
        	$('textarea[title="SummaryDetails"]').val(textContent1)
        }
        else
        {
       	$('textarea[title="SummaryDetails"]').val(textContent2)
        }    
      });     
    });

    above code is working, but Rich Text Box showing old content(textContent1) only even I am clicking Radio Button selection.

    I am really stuck here, so please help me out!!



    • Edited by Siva Padala Tuesday, August 6, 2013 2:53 PM
    Tuesday, August 6, 2013 2:49 PM

Answers

  • $(document).ready(function() {
    	var summaryDetailsRTE = $("textarea[Title='SummaryDetails']").closest("span").find("iframe[Title='Rich Text Editor']").contents().find("body");
     
        var textContent1='<div><b>Summary</b></div>'
        				+'<hr color="black">'    				
        				+'<div id="Summary-Instruction">Instructions:</div></br></br>'
        				+'<div><b>Additional Comments</b></div>'
        				+'<hr color="black">'    				
        				+'<div>Instructions:</div></br></br>'; 
        				
       var textContent2='<div><b>Questions</b></div>'
        				+'<hr color="black">'    				
        				+'<div id="Summary-Instruction">Instructions:State the question.</div></br></br>'
        				+'<div><b>Answer</b></div>'
        				+'<hr color="black">'    				
        				+'<div id="Summary-Instruction">Instructions:Provide the answer(s) to the question.</div></br></br>'
        				+'<div><b>Additional Comments</b></div>'
        				+'<hr color="black">'    				
        				+'<div>Instructions:Provide any additional information that will help readers with their questions.</div></br></br>'; 
     
      $(summaryDetailsRTE).html(textContent1);
      $('input[type="radio"]').click(function(){
        
        if($(this).val()=="option1")
        {
    		$(summaryDetailsRTE).html(textContent1);
        }
        else
        {
    		$(summaryDetailsRTE).html(textContent2);
        }    
      });
    Let me know if that helps?
    Friday, October 4, 2013 1:06 PM