This simple assignment is to create a javascript form that enables calculation of two numbers that are entered by a user.
Disclaimer: This is not the best approach for systems that perform regular calculations and manage large amounts of data; there are better programming languages for that. Javascript is best used for small functions on Internet pages where data can be simply displayed and calculations performed. Further programming can store the data, only if a database exists, and is best used if immediately used while in a browser session, otherwise, the data is lost when the page changes, is refreshed, or closed. Code writing must take place in order to store the calculated number or result into a database field for later use. Databases are best used for this, but for simplicities sake, Javascript is used to present small calculations for quick on screen use.
WordPress (php coding) does not allow javascript to be directly written in the HTML portion of the posts and pages. This is to protect the site from bad or malicious code. It requires the installation of a plugin in order for Javascript to be used. This is done to easily disable javascript or enable it to allow its functioning and also set it apart from the other code because it is different. For the purposes of the assignment, Javascript Code plugin will be installed and tested.
Here is the Javascript Code:
Must be written in two blocks, using the Code and HTML blocks and the code does not work.
function multiplyBy()
{
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
document.getElementById("result").innerHTML = num1 * num2;
}
function divideBy()
{
num1 = document.getElementById("firstNumber").value;
num2 = document.getElementById("secondNumber").value;
document.getElementById("result").innerHTML = num1 / num2;
}
The Result is :
It is easier to just use a calculator and teach Javascript for its real purpose: Code is supposed to make life easier, not harder. If numbers need to be calculated, it is better to plan an entire project and select the best solution for the implementation approach. Installing Javascript requires a risk assessment to an already functioning site, as well as research, selection, and testing.
Two plugins were tested, nothing functioned and instructions were not straightforward.
Findings: Javascript is not recommended for small jobs with WordPress and the time investment is better spent on Forms that perform calculation on datafields, not individualized programming code snippets that will not be used for multiple purposes.
The research will continue and the programmer will continue to prove Javascript’s non-necessity and incompatibility with other, simplified options – pointing out the requirement for Long Term planning of Technical Design, where systems must go through a selection and test process prior to purchasing and use.
One cannot ‘pickup’ and learn JavaScript using Visual Studio, but they can install it and produce a quick result – a non visually based system. When a visually based system is used, merging two creates problems where a search and requirement for simpler methods are preferred and available.