"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.