Help wanted: Simple selection, multiply and display

Discussion in 'Javascript' started by slitchfield@ukonline.co.uk, Dec 10, 2005.

  1. Guest

    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, 2005
    #1
    1. Advertising

  2. Patient Guy Guest

    "" <> wrote in
    news::

    > 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.
     
    Patient Guy, Dec 11, 2005
    #2
    1. Advertising

  3. Guest

    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, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    19,159
    Thomas Stanka
    Dec 15, 2005
  2. Harvey
    Replies:
    0
    Views:
    721
    Harvey
    Jul 16, 2004
  3. Harvey
    Replies:
    1
    Views:
    856
    Daniel
    Jul 16, 2004
  4. Simon Niederberger
    Replies:
    2
    Views:
    16,532
    Christian Kaufhold
    Jan 7, 2005
  5. Andrew Crowe
    Replies:
    1
    Views:
    4,478
    Andrew Crowe
    Sep 13, 2004
Loading...

Share This Page