JavaScript calculator and form
-
I’ve made a simple JavaScript calculator where the user selects two variables in a table, which are assigned values dependent on their choice, and then click an OnClick button tag below the table giving them an answer below the button.
‘calc.js’ is the JavaScript file that does the calculation. Inside calc.js the main function
calculate()is called by the button on the page that user sees:<button onclick="calculate()">Calculate</button>.The JavaScript works, I currently have it in a standalone html file, which I’ve included on a WordPress page using an iframe. Fine for now for users who are none the wiser but I’d rather have the calculator actually in my WordPress site.
So I put this in the header.php file:
<?php if (is_page(244)) { echo '<script type="text/javascript" src="/calc.js"></script>'; } ?>And then I put the table code into the editor for the page, and the table itself shows up fine. But when I enter my two variables and click the button, nothing happens.
So can any of you guys help me out?
The topic ‘JavaScript calculator and form’ is closed to new replies.