470,615 Members | 2,182 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,615 developers. It's quick & easy.

Help wanted: Simple selection, multiply and display

Sorry if this is real beginner's stuff, but I'm an old-school HTML guy
and this is all another world to me.

Is there an easy way to get the user to specify a number from 1 to 5
(in a pick list or radio button or similar) and get a javascript
routine to multiply it by another hard-coded number (e.g. 7) and
display the result further down the page?

Thanks,
Steve Litchfield

Dec 10 '05 #1
2 1385
"sl*********@ukonline.co.uk" <sl*********@ukonline.co.uk> wrote in
news:11**********************@o13g2000cwo.googlegr oups.com:
Sorry if this is real beginner's stuff, but I'm an old-school HTML guy
and this is all another world to me.

Is there an easy way to get the user to specify a number from 1 to 5
(in a pick list or radio button or similar) and get a javascript
routine to multiply it by another hard-coded number (e.g. 7) and
display the result further down the page?


There is a way. 'Easy' is a term that means different things to different
people.

Working in parts to your post:

1. Specifying number from 1 to 5

You have fairly well described what it is you need to do with respect to
HTML. Either set up a drop-down (select) list or set of radio buttons to
provide the user with the options that you want to limit him/her to. You
will then want a handler to do something once selection is made: either
an "onchange" event for the select/radio control or a button provided to
the user to indicate that the selection is made or final (the use of the
button is better, unless you want the user to have the option of seeing a
result updated with each selection).

2. Multiplying by hard-coded number

You then have the handler call the function that will do items 2 and 3 in
this descriptive outline. The function will recover the value from the
(form) control set by the user, do the math that you want, and produce the
result. The result will be displayed as described below.

3. Displaying Result

You will want to have a DIV element with an 'id' attribute as part of your
document. It can be empty and/or set not to display through Javascript.
Within the function that gets the value and does the math, you will
reference that DIV and add text as a child node of that DIV. That text
content will be your result. You will want to learn particularly about
the methods 'document.createTextNode()' and 'document.createElement()' in
manipulating HTML documents dynamically. I recommend browsing through the
DOM Core and HTML specifications found at http://www.w3.org. Once your
familiar with these interfaces, you will get pretty much what you want.

I would think that given my descriptive outline above, you have sufficient
information for proceeding with coding. Let's see what you come up with,
and come back here if your code fails to work and you are stuck.

Dec 11 '05 #2
Thanks, you've been brilliant! That's all printed out and I'll get this
sorted (hopefully!) over Christmas. I've also found a friend with some
experience, so between us....

Thanks again
Steve

Dec 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Donna | last post: by
31 posts views Thread by da Vinci | last post: by
5 posts views Thread by ritchie | last post: by
2 posts views Thread by Daniel | last post: by
1 post views Thread by JWest46088 | last post: by
1 post views Thread by KiMcHeE | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.