Skip to main content

add text editor dynamically on click add button add new and on click remove button remove field

<html>

<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.ckeditor.com/4.11.1/full/ckeditor.js"></script>
<!-- <script src='https://cloud.tinymce.com/stable/tinymce.min.js'></script> -->

</head>

<body>
<div class="input_fields_wrap">
<button class="add_field_button">Add More Fields</button>
<div><input type="text" name="mytext[]"><br><textarea class="form-control ckeditor" name="title[]" required></textarea></div>
</div>

<script>
$(document).ready(function() {
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID

var x = 1; //initlal text box count
$(add_button).click(function(e) { //on add input button click
e.preventDefault();
if (x < max_fields) { //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input type="text" name="mytext[]"/><br><textarea id="editor' + x + '" class="form-control" name ="title[]" required></textarea><br><a href="#" class="remove_field">Remove</a></div>'); //add input box
}
addTinyMCE();
});

$(wrapper).on("click", ".remove_field", function(e) { //user click on remove text
e.preventDefault();
$(this).parent('div').remove();
x--;
});

function addTinyMCE() {


// Initialize
CKEDITOR.replace('editor' + x);
}
});
</script>
</body>

</html>

Comments

Popular posts from this blog

laravel file manager sorting by time default

Ref :  https://github.com/UniSharp/laravel-filemanager/issues/337 To load files order by "time DESC" you can change the code in vendor/unisharp/laravel-filemanager/src/traits/LfmHelpers.php public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; } return strcmp($a->{$key_to_sort}, $b->{$key_to_sort}); }); return $arr_items; } with public function sortFilesAndDirectories($arr_items, $sort_type) { if ($sort_type == 'time') { $key_to_sort = 'updated'; } elseif ($sort_type == 'alphabetic') { $key_to_sort = 'name'; } else { $key_to_sort = 'updated'; ...

creating subdomain and upload

step 1: create subdomain step 2: create database step 3: set username and passwore to database step 4: change php version from multiphp manager to 7.1 or 7.2 step 5: open subdomain from file manager and remane public step 6: upload zip project file step 7: unzip and move all file outside of the projct name folder i.e subdomain vitra siddhai sabai files and folder rakhdini step 8: edit env file db name, user name, and password