Reputation: 127
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.
Upvotes: 1
Views: 4245
Reputation: 3925
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/
Upvotes: 2