Wednesday, September 7, 2022
HomeWordPress Developmentphp - Load wp_editor on button click on

php – Load wp_editor on button click on


I’m engaged on making a type that whenever you click on a button, new components are added to the shape. I’ve it working besides I am having hassle determining the way to load a wp_editor once I click on the button. The next code is what I’ve.

HTML/PHP

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button onclick="add()">Add</button>
<type motion="" methodology="submit">
    <p id="acc1">
        <b>Title: </b><enter sort="textual content" identify="accvalue1">
        <?php
        $content material="";
        $editor_id = 'accDesc1';
        $settings = array(
            'textarea_name' => 'txtDesc',
            'textarea_rows' => 10,
        );
        ?><div fashion="width: 70%"><?php
        $neweditor = wp_editor( $content material, $editor_id, $settings );
        echo $neweditor;
        ?></div><?php
        ?>
    </p>
    <div id="new_chq"></div>
    <enter sort="hidden" worth="1" id="total_chq">
</type>

Javascript

<script>
    perform add(){
        var new_chq_no = parseInt($('#total_chq').val())+1;
        var new_input="<p id='acc"+new_chq_no+"'><b>Title: </b><enter sort="textual content" id='accvalue"+new_chq_no+"' identify="accvalue"+new_chq_no+""><button id='"+new_chq_no+"' onclick='take away(this.id)''>take away</button></p>";
        $('#new_chq').append(new_input);
        $('#total_chq').val(new_chq_no);
    }
    perform take away(clicked_id){
        var last_chq_no = $('#total_chq').val();
        if (clicked_id > 1) {
            $('#acc'+clicked_id).take away();
            if (clicked_id < last_chq_no) {
                var startid = +clicked_id + 1;
                for (let i = startid; i <= last_chq_no; i++) {
                    var newid = +i - 1;
                    doc.getElementById('acc'+i).id = 'acc'+newid;
                    doc.getElementById('accvalue'+i).id = 'accvalue'+newid;
                    doc.getElementById(i).id = newid;
                }
            }
            $('#total_chq').val(last_chq_no-1);
        }
    }
</script>

Like I stated, every little thing works, I simply have to know the way to load the wp_editor once I click on the button. Any assistance is appreciated.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments