Logo

Post to JDoodle

JDoodle offers a simple and straightforward way to allow users to execute code directly from your web page, without the need for API integration or HTML/JS scripting. This guide aims to help you implement this feature by explaining the required steps in detail.

How it works?

With JDoodle, you can display the code on your webpage styled as you wish. When a user decides to run the code by clicking on a link or button, a POST request containing the code snippet is sent to JDoodle. The user can then execute and interact with that code on JDoodle’s platform.

Sample code for form submission

To get started, simply include the following form in your HTML page:

<form action="https://www.jdoodle.com/api/redirect-to-post/online-java-compiler" method="post">
  Script: <textarea name="initScript" rows="8" cols="80"></textarea>
  <input type="submit" value="Submit">
</form>

In this sample code, replace “online-java-compiler” with the IDE of your choice, for instance:

  • For C programming: c-online-compiler
  • For Python3: python3-programming-online

These IDE types can usually be found in the URLs when you visit JDoodle’s platform.

Sample integration code

Here’s a sample HTML code that integrates the JDoodle form:

<title>Post to JDoodle</title>

        Test page for Post to JDoodle
        <pre>public class MyClass {
    public static void main(String args[]) {
        System.out.println("Program from my blog");
    }
}
        </pre>
        <input type="button" value="Try this in JDoodle" id="tryThis">
        <form id="codeForm" action="https://www.jdoodle.com/api/redirect-to-post/online-java-compiler" method="post" style="display: none" target="_blank">
          <textarea name="initScript" rows="8" cols="80">public class MyClass {
    public static void main(String args[]) {
      System.out.println("Program from my blog");
    }
}
        </textarea>
        </form>
        <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
        <script>
          $("#tryThis").click(
            function() {
              $("#codeForm").submit();
            }
          );
        </script>

To function correctly, simply save this code in a .txt file and change the extension to .html.

Troubleshooting

If you encounter any issues while implementing this feature, consider the following:

  • Ensure the form HTML code is correctly placed within your webpage if the form doesn’t appear.
  • Double-check that the IDE name is correctly replaced in the form action URL if the code doesn’t execute.
  • Verify your internet connection and that the JDoodle website is accessible if the page is not redirecting.