1

I'm trying to set default text on Enhanced Rich Text field in Default New Form. I tried code from here and here and some other places, but nothing works for me.

My target field doesn't have a title, so I try to select it by it's ID.

var DesciptionID = "ctl00_m_g_80cbe371_4e9b_405f_afdd_b251a2b45ec2_ctl00_ctl05_ctl01_ctl00_ctl00_ctl04_ctl00_ctl00_TextField_inplacerte";
var ImpactBoxID = "ctl00_m_g_80cbe371_4e9b_405f_afdd_b251a2b45ec2_ctl00_ctl05_ctl03_ctl00_ctl00_ctl04_ctl00_ctl01";

$(document).ready($(function() {
  $("#"+ImpactBoxID).change(function() {
    if(this.checked) { 
      alert("checked");
      $("#"+DesciptionID).val("paragraph"); // <<<<

      $(":input[title=Title]").val("here is title"); //this one works. single line field. it also has a title
    }
  });

I was able to achieve my goal on plain text, but i need enhanced one.

Also here is whole cell in case I'm getting the wrong ID.

1 Answer 1

2

I think what you want to do is check your selectors, is that ID consistent? In my experience, it's not.

I would change them to be this (NOTE: assuming divs):

$(function () {
    $("#" + ImpactBoxID).change(function () {
        if (this.checked) {
            $('div[id$="TextField_inplacerte"').text("paragraph"); // $= means "ends with"
                                                                   // also unless it's an input use text instead. Val sets input values.
            $(":input[title=Title]").val("here is title"); //this one works. single line field. it also has a title
        }
    });
});

Fiddle: http://jsfiddle.net/KyleMuir/7tKJ3/

Resources:

Ends with selector: http://api.jquery.com/attribute-ends-with-selector/

.text(): http://api.jquery.com/text/

3
  • I'll try to change those selectors. However your code didn't work, the field is still empty. Also the Title field wasnt changed too so it means the line before had an error?
    – andflow
    Apr 13, 2014 at 21:33
  • Please check the fiddle, I have attempted to reproduce your issue. I also fixed up your code, there was some issues with your document.ready stuff.
    – Kyle Muir
    Apr 13, 2014 at 21:48
  • I dont have access to consele. And this one also didnt work. I tried writing into that field by hand and checked on firebug. It seems it writes not to <div> but to <p>. &#8203; in my attached example.
    – andflow
    Apr 13, 2014 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.