vendredi 31 juillet 2020

How do I create a "Play Code Snippet" Button with JavaScript? [closed]

I am trying to create a function that allows the author of a document to execute code that they have entered. The page looks like this:

enter image description here

As you can see the author can enter code snippets, however, I would like them to be able to check what they have entered is correct. I have an idea similar to what is used on stack overflow. I want to reader to be able to click the "Play Code Snippet" Button and the result to be shown. At the moment the result is hardcoded and once the user pressed the show button the webpage looks like this:

enter image description here

This is the jQuery for that:

<script>
    (function () {
        $(document).ready(function(){
            $('#showCode').click(function(){
                $(".resultSection").addClass("show");
            });

            $('#hideResult').click(function(){
                $(".resultSection").removeClass("show");
            });
        });
    })();
</script>

How do I take the code/input from the code section (.codeSection) and execute it using javascript to then output the correct response?

I am also using Laravel, are there any helpers that it could provide?

Any help would be great! Thanks



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2PctKK6
via IFTTT

Aucun commentaire:

Enregistrer un commentaire