javascript - Load template on select change -


is there way, using javascript, load template whenever specific select tag, changes value? example, user changes value of select nothing "template_1" ckeditor should load "template_1".

html:

<select id="tipe">   <option>template_1</option> </select>  <textarea class="ckeditor form-control html" id="motivo" name="motivo" rows="6" data-error-container="#editor2_error"></textarea> 

javascript:

ckeditor.replace('motivo'); $('#tipe').change(function(){     var template = $(this).val();     ////code here replace template }); 

i have preloaded "template_1" on ckeditor templates.

define different templates in object. then, add event listener input box, , set ckeditor content.

html:

<select id="tipe">   <option></option>   <option value="template_1">template 1</option>   <option value="template_2">template 2</option> </select>  <textarea class="ckeditor form-control html" id="motivo" name="motivo" rows="6" data-error-container="#editor2_error"></textarea> 

javascript:

var templates={}; templates["template_1"]="<p>this first template</p>"; templates["template_2"]="<p>this second template</p>"; $('#tipe').change(function(){     var template = $(this).val();     ckeditor.instances["motivo"].setdata(templates[template]) }); 

example: http://jsfiddle.net/8ybxpku8/


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -