Javascript to interact with textarea?

  • 18 October 2018
  • 1 reply
  • 69 views

Badge +8

Greetings,

I'm looking into using a different RichText control than K2's out of the box. (performance implications when 40+ are on a form)...

I need some assistance with the javascript that can properly set the internalHTML of a K2 textarea control so that it's available for later use by K2 rules. 

For instance.. this will set a value in datalabels .. $("[name='txt_FName']").SFCLabel('option', 'text', 'Vermaniac');

 

What's the similar code for a text area? It appears that textareas don't have a name attribute. And if I use document.getElementById('<textarea id>').innerHTML = 'This is something'; the value will get into the DOM, but running a rule to then read the value doesn't return "This is something"


1 reply

Userlevel 4
Badge +13

Good day Dgilmour,


 


By the looks of you requirement and explanation I can see that you are planning on providing the text area control with a specified value, I presume the text area would not be the end of the world if the control is not changeable by the user in that case?  If this is the case and the control can be set to not be changeable then the below will work for your requirement.


 


Text area controls do not have a value attribute, but they still use .val(). With that being said you would need to make use of that in order to retrieve or change the data in your text area control. I recomend using the following Jquery snippet to change the text in the text area contol:


Important Note: Keep in mind that you will need to set the text area control to be disabled as the control is designed to refire when it detects a mouse click on the control itself. If the control is not disabled after the code has fired and a user accidentally clicks on the text area control, the data will revert to what is was before the code executed in which case you will be passing the wrong data around in the form.


<script>$('#PLACE YOUR TEXTAREA CONTROLS ID HERE').val('ANY TEXT CAN BE PLACED HERE');</script>

 


Should you feel that this post is of use and or an accurate solution to the raised question, I kindly encourage you to mark it as such using the 'Mark as Solution', 'Kudo' andor ‘Me Too’ options.


 


Kind Regards


Raymond


 

Reply