locked
jquery can't find richtextbox?

    Question

  • I had some textarea textbox and was having no problem finding and changing it's value with jquery as follows:

      $('textarea[title$="BodyText"]').val('hello');

    But I needed the texteara multiline textbox  to be rich textbox, so I added another column type Richtextbox, but I can't seem to find it with jquery.. looking at the rendered code, all all see is some script after a normal textarea.

    If I boil down the code to the just the textarea and test in in jsfiddle.. naturally it works. Any ideas.. i have both textboxs next to each other with the exact same code, one works the other does not. I'm at the changeevent for another dropdown, so I know code placement is not the issue.

    Thanks.

             
    <span dir="ltr">
    <textarea name="ctl00$PlaceHolderMain$g_d63cd1e2_dcca_4553_8a0c_df6047a0a489$ff5_1$ctl00$ctl00$TextField" rows="6" cols="20" id="ctl00_PlaceHolderMain_g_d63cd1e2_dcca_4553_8a0c_df6047a0a489_ff5_1_ctl00_ctl00_TextField" title="BodyText" class="ms-long" dir="none"></textarea>

    <input name="ctl00$PlaceHolderMain$g_d63cd1e2_dcca_4553_8a0c_df6047a0a489$ff5_1$ctl00$ctl00$TextField_spSave" type="HIDDEN" id="ctl00_PlaceHolderMain_g_d63cd1e2_dcca_4553_8a0c_df6047a0a489_ff5_1_ctl00_ctl00_TextField_spSave" />
       

    < script>if (browseris.ie5up && browseris.win32 && !IsAccessibilityFeatureEnabled()){RTE_ConvertTextAreaToRichEdit("ctl00_PlaceHolderMain_g_d63cd1e2_dcca_4553_8a0c_df6047a0a489_ff5_1_ctl00_ctl00_TextField", true, false, "", "1033", null, null, null, null, null,"Compatible", "\u002fucharterror",null,null,null,null);}else{document.write("&nbsp;<br><SPAN class=ms-formdescription><a href='javascript:HelpWindowKey(\"nsrichtext\")'>Click for help about adding basic HTML formatting.</a></SPAN>&nbsp;<br>");};</script>

     One thing I am seeing.. and I can't see how this is affecting rendered code is that in design mode in SPD  the rich textbox does not display correctly saying Failed to render because of an error in muliple lines of text.  It's custom List newform.

     

     




    Thursday, August 25, 2011 10:29 PM

Answers

  • Hi,

    I have the same problem as you. I solved it by addressing the input of the richtext as follows:

    When using only one column, then you could write content in the richtext by using this code:
    
    $('input[id$="TextField_spSave"]').val('myContent);
    
    The above scenario is not really secure. It breaks when you are using two boxes of this type.
    
    You can either start looping over and differentiate it by using the occurence count and set the value.
    
    Another alternative could be to use the default form structure and reference the item as follows:
    
    $('nobr:contains("BodyText")').closest('tr').find('input[id$="TextField_spSave"]').val('myContent);
    

    Unfortunately, I did not find more elegant solutions so far.

     

    Note: I am working on a codeplex project that provides a library to reference easily these fields. It is still work-in-progress.

    Here the link: http://listformmanipulation.codeplex.com/

     

    br,

    Patrick



    follow me if you want on:
    my blog http://www.lamber.info
    Twitter: @patricklamber
    • Marked as answer by o365spo Saturday, August 27, 2011 10:50 AM
    Saturday, August 27, 2011 8:05 AM

All replies

  • Hi,

    I have the same problem as you. I solved it by addressing the input of the richtext as follows:

    When using only one column, then you could write content in the richtext by using this code:
    
    $('input[id$="TextField_spSave"]').val('myContent);
    
    The above scenario is not really secure. It breaks when you are using two boxes of this type.
    
    You can either start looping over and differentiate it by using the occurence count and set the value.
    
    Another alternative could be to use the default form structure and reference the item as follows:
    
    $('nobr:contains("BodyText")').closest('tr').find('input[id$="TextField_spSave"]').val('myContent);
    

    Unfortunately, I did not find more elegant solutions so far.

     

    Note: I am working on a codeplex project that provides a library to reference easily these fields. It is still work-in-progress.

    Here the link: http://listformmanipulation.codeplex.com/

     

    br,

    Patrick



    follow me if you want on:
    my blog http://www.lamber.info
    Twitter: @patricklamber
    • Marked as answer by o365spo Saturday, August 27, 2011 10:50 AM
    Saturday, August 27, 2011 8:05 AM
  • elegant enough.  Thanks a bunch.


    Thank You.

     

    Saturday, August 27, 2011 10:50 AM