#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0

    Create an array of values to be calculated


    Good evening to all!

    Code:
    <html>
    <head>
    <title>Edit a Model</title>
    
    <script type="text/javascript"> 
    function calcform() 
    { 
    with (document.form1) 
    { var m_bed_l_feet = ~~(m_bed_l.value / 12);
      m_bed_l_inches = m_bed_l.value - (12 * m_bed_l_feet);
      var m_bed_l_text = m_bed_l_feet + "'" + m_bed_l_inches + '"';
      m_bed_l_txt.value = m_bed_l_text}
    } 
    </script> 
    
    </head>
    <body>
    <form name=form1 method="post" action="<?php echo $PHP_SELF;?>" >
    <table>
    <tr><td>Master Bedroom:</td><td><input type="text" size="2" name="m_bed_l" value=187>" = </td><td><input type="text" size="2" name="m_bed_l_txt" style="border:none"></td></tr>
    </table>
    <input type="button" id="Calculate" value="Calculate" onclick="calcform()" /> 
    </form>
    </html>
    OK, I have the above form that will pull the length value m_bed_l from my database and convert that from inches to feet and inches.

    I want to do this for:
    - m_bed_w
    - _2_bed_l
    - _2_bed_w
    and about 30 other values.

    How do I build an array of all the values I want converted, convert them in a recursive loop and spit out all the values into the appropriate text boxes?

    This is the idea, but it doesn't work:

    Code:
    <html>
    <head>
    <title>Edit a Model</title>
    
    <script type="text/javascript"> 
    function calcform() 
    { 
    with (document.form1) 
    {var myrooms = new Array();
    myrooms[0] = "m_bed_l";
    myrooms[1] = "m_bed_w";
    myrooms[2] = "_2_bed_l"; 
    myrooms[3] = "_2_bed_w"; 
    myrooms[4] = "_3_bed_l"; 
    myrooms[5] = "_3_bed_w"; 
    myrooms[6] = "l_room_l"; 
    myrooms[7] = "l_room_w"; 
    myrooms[8] = "m_room_l"; 
    myrooms[9] = "m_room_w"; 
    myrooms[10] = "d_room_l"; 
    myrooms[11] = "d_room_w"; 
    myrooms[12] = "den_l"; 
    myrooms[13] = "den_w"; 
    
    for (var i=0;i<myrooms.length;i++)
    {
    
    var myrooms[i]_feet = ~~(myrooms[i].value / 12);
      myrooms[i]_inches = myrooms[i].value - (12 * myrooms[i]_feet);
      var myrooms[i]_text = myrooms[i]_feet + "'" + myrooms[i]_inches + '"';
      myrooms[i]_txt.value = myrooms[i]_text}
    } 
    
    }
    </script> 
    
    </head>
    <body>
    <form name=form1 method="post" action="<?php echo $PHP_SELF;?>" >
    <table>
    <tr><td>Master Bedroom:</td><td><input type="text" size="2" name="m_bed_l" value=187>" = </td><td><input type="text" size="2" name="m_bed_l_txt" style="border:none"></td></tr>
    </table>
    <input type="button" id="Calculate" value="Calculate" onclick="calcform()" /> 
    </form>
    </html>
    I decided to do the cut & paste method, and this works too, just kinda liked the idea of an array better:
    Code:
    <html>
    <head>
    <title>Edit a Model</title>
    
    <script type="text/javascript"> 
    function calcform() 
    { 
    with (document.form1) 
    {
    var m_bed_l_feet = ~~(m_bed_l.value / 12); m_bed_l_inches = m_bed_l.value - (12 * m_bed_l_feet);  var m_bed_l_text = m_bed_l_feet + "'" + m_bed_l_inches + '"';  m_bed_l_txt.value = m_bed_l_text;
    var m_bed_w_feet = ~~(m_bed_w.value / 12); m_bed_w_inches = m_bed_w.value - (12 * m_bed_w_feet);  var m_bed_w_text = m_bed_w_feet + "'" + m_bed_w_inches + '"';  m_bed_w_txt.value = m_bed_w_text;
    var _2_bed_l_feet = ~~(_2_bed_l.value / 12);  _2_bed_l_inches = _2_bed_l.value - (12 * _2_bed_l_feet);  var _2_bed_l_text = _2_bed_l_feet + "'" + _2_bed_l_inches + '"';  _2_bed_l_txt.value = _2_bed_l_text;
    var _2_bed_w_feet = ~~(_2_bed_w.value / 12);  _2_bed_w_inches = _2_bed_w.value - (12 * _2_bed_w_feet);  var _2_bed_w_text = _2_bed_w_feet + "'" + _2_bed_w_inches + '"';  _2_bed_w_txt.value = _2_bed_w_text;
    var _3_bed_l_feet = ~~(_3_bed_l.value / 12);  _3_bed_l_inches = _3_bed_l.value - (12 * _3_bed_l_feet);  var _3_bed_l_text = _3_bed_l_feet + "'" + _3_bed_l_inches + '"';  _3_bed_l_txt.value = _3_bed_l_text;
    var _3_bed_w_feet = ~~(_3_bed_w.value / 12);  _3_bed_w_inches = _3_bed_w.value - (12 * _3_bed_w_feet);  var _3_bed_w_text = _3_bed_w_feet + "'" + _3_bed_w_inches + '"';  _3_bed_w_txt.value = _3_bed_w_text;
    var l_room_l_feet = ~~(l_room_l.value / 12);  l_room_l_inches = l_room_l.value - (12 * l_room_l_feet);  var l_room_l_text = l_room_l_feet + "'" + l_room_l_inches + '"';  l_room_l_txt.value = l_room_l_text;
    var l_room_w_feet = ~~(l_room_w.value / 12);  l_room_w_inches = l_room_w.value - (12 * l_room_w_feet);  var l_room_w_text = l_room_w_feet + "'" + l_room_w_inches + '"';  l_room_w_txt.value = l_room_w_text;
    var m_room_l_feet = ~~(m_room_l.value / 12);  m_room_l_inches = m_room_l.value - (12 * m_room_l_feet);  var m_room_l_text = m_room_l_feet + "'" + m_room_l_inches + '"';  m_room_l_txt.value = m_room_l_text;
    var m_room_w_feet = ~~(m_room_w.value / 12);  m_room_w_inches = m_room_w.value - (12 * m_room_w_feet);  var m_room_w_text = m_room_w_feet + "'" + m_room_w_inches + '"';  m_room_w_txt.value = m_room_w_text;
    var d_room_l_feet = ~~(d_room_l.value / 12);  d_room_l_inches = d_room_l.value - (12 * d_room_l_feet);  var d_room_l_text = d_room_l_feet + "'" + d_room_l_inches + '"';  d_room_l_txt.value = d_room_l_text;
    var d_room_w_feet = ~~(d_room_w.value / 12);  d_room_w_inches = d_room_w.value - (12 * d_room_w_feet);  var d_room_w_text = d_room_w_feet + "'" + d_room_w_inches + '"';  d_room_w_txt.value = d_room_w_text;
    var den_l_feet = ~~(den_l.value / 12);  den_l_inches = den_l.value - (12 * den_l_feet);  var den_l_text = den_l_feet + "'" + den_l_inches + '"';  den_l_txt.value = den_l_text;
    var den_w_feet = ~~(den_w.value / 12);  den_w_inches = den_w.value - (12 * den_w_feet);  var den_w_text = den_w_feet + "'" + den_w_inches + '"';  den_w_txt.value = den_w_text;
    }
    }
    </script> 
    
    </head>
    <body>
    <form name=form1 method="post" action="<?php echo $PHP_SELF;?>" >
    <table>
    <tr><td>Master Bedroom:</td><td><input type="text" size="2" name="m_bed_l" value=187>" = </td><td><input type="text" size="2" name="m_bed_l_txt" style="border:none"></td></tr>
    </table>
    <input type="button" id="Calculate" value="Calculate" onclick="calcform()" /> 
    </form>
    </body>
    </html>



    Thanks everyone!

    -Dave
  2. #2
  3. Old Fart
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Location
    Chicago
    Posts
    108
    Rep Power
    5

    Array of what.


    It looks like you are creating an array of room names. I think an array of values would work better. eg:
    Code:
    myrooms[0] = m_bed_l.value; 
    myrooms[1] = m_bed_w.value;
    etc. . .
    And
    Code:
    var feet; 
    var inches; 
    var text; 
    for (var i=0;i<myrooms.length;i++) {
       feet = ~~(myrooms[i] / 12);
       inches = myrooms[i] - (12 * feet);
       myrooms[i] = feet + "'" + inches + '"'; 
    }
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    2
    Rep Power
    0
    Thank you, richpri.

    I had tried several times to get an array to work, yours does what I need!

IMN logo majestic logo threadwatch logo seochat tools logo