How to write programs in your website and redirect it in JDoodle online compiler ?
There may be situations where it may be required to run a piece of code that has been entered by the user. This can be done by using JDoodle. We can write our programs in any programming language on our website page and it can be redirected to the JDoodle online compiler to be run on that website.
Note: It is not mandatory to sign in or register in JDoodle for using this method.
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML course.
We will be doing this using a form, a textarea and a submit button. The action attribute of the form can be used to redirect the page to the required programming language compiler. The textarea will be used to allow the user to write the program and the submit button will redirect to the respective programming language online compiler. On the redirected page, we can easily run our program in the JDoodle compiler.
Steps to follow:
Step 1: Open jdoodle and select the programming language that is required.
Step 2: Copy the end of the URL of the compiler page that opens. This will be the compiler URL that we will use to redirect our code.
Step 3: Use the code below that contains all the elements required to redirect the page. The action attribute is defined with the redirect API URL of JDoodle and the end of the URL copied from above is used with it. This will cause the redirect whenever the form is submitted using the button.
The below examples demonstrate this approach in action:
Example 1: Using the C compiler of JDoodle
Example 2: Using the C++ Compiler of JDoodle