Displaying the sum

I’m creating a very simple Rails application where I enter “First
number” and then “Second number” and get the result in the “Sum”.

Those are some files:

show.html.erb: http://pastie.org/private/1cydign77xnijlrb7mjvng
_form.html.erb: http://pastie.org/private/narsz5oeuafahclqtvmwq

What do I want?

I just want the Sum to be DISPLAY the summation result automatically
after entering the first and second numbers, without having a text box
beside some.

I think it may be a HRML/CSS touch?

What should I do here?

Thanks.

Abder-Rahman A. wrote:

I’m creating a very simple Rails application where I enter “First
number” and then “Second number” and get the result in the “Sum”.

Those are some files:

show.html.erb: http://pastie.org/private/1cydign77xnijlrb7mjvng
_form.html.erb: http://pastie.org/private/narsz5oeuafahclqtvmwq

What do I want?

I just want the Sum to be DISPLAY the summation result automatically
after entering the first and second numbers, without having a text box
beside some.

I think it may be a HRML/CSS touch?

What should I do here?

Thanks.

If you want to populate the sum field with the result of first number +
second number, consider JavaScript.

Thanks Pale, cannot I use CSS for that. I’m actually not aware of
Javascript.

Abder-Rahman A. wrote:

Thanks Pale, cannot I use CSS for that. I’m actually not aware of
Javascript.

Do no not use CSS for this; CSS is for styling your page. If you’re not
familiar with JavaScript, can I suggest you start here:

Pale H. wrote:

Abder-Rahman A. wrote:

Thanks Pale, cannot I use CSS for that. I’m actually not aware of
Javascript.

Do no not use CSS for this; CSS is for styling your page. If you’re not
familiar with JavaScript, can I suggest you start here:
JavaScript Tutorial

Got you Pale.

So, you mean that even I have the result, I cannot display it using CSS
since it is for styling?

I’ll check Javascript then.

Thanks a lot.

Thanks a lot Marnen for your nice recommendations and advice.

Abder-Rahman A. wrote:

Pale H. wrote:

Abder-Rahman A. wrote:

Thanks Pale, cannot I use CSS for that. I’m actually not aware of
Javascript.

Do no not use CSS for this; CSS is for styling your page. If you’re not
familiar with JavaScript, can I suggest you start here:
JavaScript Tutorial

Got you Pale.

So, you mean that even I have the result, I cannot display it using CSS
since it is for styling?

Right. Basically, if you want dynamic behavior on the client side, you
need JavaScript. Remember to provide an alternative for those without
JavaScript! (Look up “progressive enhancement” for a good way to do
this.)

I’ll check Javascript then.

Your first stop should be Doug Crockford’s website (
http://www.crockford.com ). In particular, note and follow his
recommendation to put JavaScript in separate files rather than mixing it
in with HTML. If you want a book, I recommend David Flanagan’s
JavaScript: The Definitive Guide; Doug Crockford’s JavaScript: The Good
Parts seems good also. http://www.javascriptkit.com is a good basic
language reference.

Thanks a lot.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]