user1031742
user1031742

Reputation: 424

single page various calculation scripts

I want to incorporate on some of my pages various very simple calculators - user inputs one or two variables (height, weight .. whatever) clicks submit button and get's a result instantly on the same page. There are many formulas that I want to use. My question as a non programmer is - what is the best way to approach this. Shouls I be looking for some javascript scripts/forms? Can you point me to right direction here?

Thank you very much.

Upvotes: 0

Views: 96

Answers (2)

username
username

Reputation: 4308

I agree with people who suggests you to learn basics of programming. On the other hand this is the direct answer to your question. (using jQuery)

HTML

<form>
    <input type="text" id="var1" />
    +
    <input type="text" id="var2" />
    <input type="submit" value="=" />
</form>
<span id="result"></span>​

JAVASCRIPT

$('form').submit(
    function(e) {
        e.preventDefault();
        $('#result').text(parseInt($('#var1').val())+parseInt($('#var2').val()));           
    }
);​

http://jsfiddle.net/XvQjb/

Upvotes: 1

Michael Malinovskij
Michael Malinovskij

Reputation: 1422

Here is a right direction for you: http://www.codecademy.com/

That site provide easy (probably the easiest) way to learn basics of JavaScript.

Upvotes: 1

Related Questions