How do I go about doing this?

Discussion in 'JavaScript' started by flyboynm, Nov 27, 2011.

  1. #1
    I need an idea of how to do something with arrays.

    I want to be able to have 2 sets of radio boxes such as:

    
    <form name="chose" id="nummeals" action>
          <input type="radio" name="choice" onclick="chose(this, '2')" /> 2
          <input type="radio" name="choice" onclick="chose(this, '4')" /> 4
        </p>
    </form>
    <p>
    <p>
    Now choose the metal you want to steal.
    <p>
    <form name="typemetal" id="typemeal">
          <input type="radio" name="meal" onclick="chose(this, 'La')" /> lasagna 
          <input type="radio" name="meal" onclick="chose(this, 'Pi')" /> pizza
          <input type="radio" name="meal" onclick="chose(this, 'Sp')" /> spaghetti
          <input type="radio" name="meal" onclick="chose(this, 'Air')" /> air
        </p>
    </form>
    
    Code (markup):
    With these selections, I will want to be able to take multiple values for "2" and "4" via a lookup table (that is what we called it in MS excel) where it is "2" & "4" equal known values

    2 2meals,6hoursapart
    4 4meals,3hoursapart

    lasanga = 234calories,23fat
    pizza = 543calories,15fat
    spaghetti = 423calories,44fat
    air = 0,0

    I would then want to be able to take these values and do various mathematical computations - how many calories and fat based upon how many meals, how much fat per meal, etc.

    How would I go about setting up this type of page?

    I thank you in advance for any assistance you can provide me.
     
    flyboynm, Nov 27, 2011 IP
  2. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #2
    honestly i don't understand what are you trying to achieve.. maybe a precise explanation?
     
    JohnnySchultz, Nov 29, 2011 IP
  3. madmod001

    madmod001 Peon

    Messages:
    14
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    just use an array (look up table) and calculate your values in your function choose() with the values you added into you array
    or if you are populating your javascript from php and sql then just load the values directly into your events like

    choose(this, 'Air', 0);

    function choose(a,b,c){
    // do your logic and calculations here
    // e.g.
    var foo = 99;
    var answer = foo + c;
    return answer;
    }
     
    madmod001, Dec 7, 2011 IP