1

I'm basically trying to do this: LINK, now, I've used Marc's methods before and SPServices etc, so it must be something ruddy stupid on my part, because everything else from him has worked without issue (thanks Marc BTW!)

So I'm trying use the same method described there to see if there's anything in the rich text column, check the length and fire my validation stuff.

I'm unable to replicate Marcs method and I've tried various creations of my own, some a bit hopeful I'll admit, what hasn't worked is this for example:

alert(("textarea[title='Requirements']").find("*").find("body").html());

I wonder if because I've altered my forms a little, that may be the reason the code doesn't work 'out of the box', here's a screenshot of my html:

My HTML, replicating Marc's examaple from his blog

Could anyone steer me towards a solution?

The code that is suggested by Marc to read the contents of the text box is:

var systemInformation = $("textarea[Title='Requirements']").closest("span").find("iframe[Title='Rich Text Editor']").contents().find("body").html();

Which I can't get to work... for info, the error message is simply

"Object doesn't support this property or method" on all variations that I try to run.

  • Try this var systemInformation = $("iframe[Title='Rich Text Editor']").contents().find("body").html(); – Amal Hashim Dec 5 '14 at 17:29
  • Thanks Amal, I haven't tried the code, but as there are multiple iframes with that title I think it won't cover it, needs to be specific to the 'requirements' text box. – d3m0n1cd4rkn355 Dec 6 '14 at 9:57
  • Ok, in that case you can directly use the id of the iframe and use it like $('#ct100_PlaceHolderMain_g_77ed0a4b_ee91_48e3_2b152a3cde83_ff11_1...).contents().find("body").html();, make sure you replace... with the complete id if iframe – Amal Hashim Dec 6 '14 at 12:31
  • Thanks again, I'll check the iframe ID remains constant when in the office and report back, cheers. – d3m0n1cd4rkn355 Dec 6 '14 at 12:34
  • That's worked! :) The ID's are always unique for each box and remain constant between sessions etc. I ran this to test: console.log($('#ctl00_PlaceHolderMain_g_77ed0a4b_ee91_48e3_a43b_2b152a3cde8e_ff11_1_ctl00_ctl00_TextField_iframe').contents().find("body").html()); which returned <DIV>test text</DIV>. Now I just need to remove the DIV's and I've got what I need, I'll figure that out. Thanks very much Amal - BTW how do I now mark your suggestion as the answer? – d3m0n1cd4rkn355 Dec 7 '14 at 12:22
1

In that case you can directly use the id of the iframe and use it like

$('#ct100_PlaceHolderMain_g_77ed0a4b_ee91_48e3_2b152a3cde83_ff11_1...).contents‌​().find("body").html();

make sure you replace... with the complete id of iframe

If you want to get content of div, then do

find("div").html()

After body find.

  • Here I am in 2017 really appreciating your answer! This worked perfectly, thank you. – Caola Jul 6 '17 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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