Create a custom calculator in wordpress

I am new to Stack exchange as well as Wordpress. So I don't know if i am in right place asking this question. I am writing a technical blog on my wordpress site and in that blog i want to include a custom calculator where users on entering values of 3 mentioned variables, the calculator will predict the outcome of the dependent variable. Suppose for example Y = 5X + 4T. I want to build a calculator in my blog post which would allow me to enter different values of X and T and then return the value of Y accordingly. Apologies in advance if I have posted the wrong question at a wrong place. Thanks

Topic forms Wordpress

Category Web


It is possible to create such a calculator in several ways, and each method can be divided according to the degree of difficulty:

1) The easiest way is to create a calculator with the help of a plugin, like Contact Form 7 or uCalc. This option will allow you to embed calculators with a short code in the content of the page or post. Such plugins completely output calculators.

2) If you want to display a specific result without the calculator itself, you will have to contrive with the help of JavaScript. This is a slightly more complicated calculation option and assumes that you are familiar with JavaScript. For example, you can simply insert into the page some element with id inside which through the script to output the result of calculations.

3) A difficult option is to write your own plugin, which will perform the necessary calculations and output it using a special function and a short code on the pages of the site. Here you need not only JavaScript, but also PHP and Wordpress API.


Assuming you only want to display the results, not save them to the server, creating a live calculator would require a little bit of Javascript code, and creating form fields for the input.

Note that by default, you cannot add Javascript to WordPress.com sites, or a self-hosted install with kses activated. You are not subject to those restrictions if you are logged in as an administrator.

Assuming you have appropriate permissions to include Javascript within a post, you could just paste something like this into the "Text" window of your post content:

X: <input id="valX" />
T: <input id="valT" />
<input type="button" value="Calculate" onclick="javascript:result.value=(5*parseInt(valX.value))+(4*parseInt(valT.value));" />
Result: <input id="result" /> 

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.