title: How do I call a function that enters text into a read-only text-box by clicking an HTML button?
body: <p>I am trying to write a short piece of html code that, given two initial amounts, attempts to find the number greater than or equal to the first that wholly divides the second given amount. The code tries to divide the numbers, and if it is unsuccessful, adds 1 to the first number and tries to divide again, etc...</p>
  
  <p>I want the code to return the value that does wholly divide the second number AND the answer to the division (with some plain text appearing around it).</p>
  
  <p>Added to this, or at least I'd like there to be, is that upon clicking one of 5 different buttons a multiplication operation is performed on the first given number, it is rounded up to the nearest whole number, and THEN the function attempts to divide this into the second given number.</p>
  
  <p>It's difficult to explain exactly what I want without showing you the code I have so far, so here it is:</p>
  
  <hr>
  
  <pre><code>&lt;html&gt;
  
  &lt;head&gt;
  
  &lt;b&gt;Rounded Commodity Pricing:&lt;/b&gt;&lt;br&gt;
  
  &lt;/head&gt;
  
  &lt;script language="Javascript"&gt;
  
  var currency;
  
  function setCurrency(val) {
   var currency = val;
  }
  
  function finddivid(marketprice,tradevalue) { 
   var KWDex = 0.281955
   var GBPex = 0.625907
   var USDex = 1
   var CADex = 0.998727
   var EURex = 0.784594
  
  if 
    (currency == "KWD") 
    var currencyMarketprice = Math.ceil(marketprice*KWDex);
  else if
    (currency == "GBP")
    var currencyMarketprice = Math.ceil(marketprice*GBPex);
  else if 
    (currency == "USD") 
    var currencyMarketprice = Math.ceil(marketprice*USDex);
  else if 
    (currency == "CAD") 
    var currencyMarketprice = Math.ceil(marketprice*CADex);
  else if 
    (currency == "EUR") 
    var currencyMarketprice = Math.ceil(marketprice*EURex);
  
  if (tradevalue % currencyMarketprice == 0)
    return ("tonnage = " + tradevalue / currencyMarketprice + " mt, and price = " + currencyMarketprice +" " +currency +" per mt");
  else
    {for (var counter = currencyMarketprice+1; counter&lt;(currencyMarketprice*2); counter++) {
      if (tradevalue % counter == 0)
       return ("tonnage = " + tradevalue / counter + " mt, and price = " + counter +" " +currency +" per mt");}}
  }
  
  &lt;/script&gt;
  
  &lt;/head&gt;
  
  &lt;p&gt;Select currency:
  &lt;input type="button" value="KWD" OnClick="setCurrency('KWD')"&gt;
  &lt;input type="button" value="USD" OnClick="setCurrency('USD')"&gt;
  &lt;input type="button" value="GBP" OnClick="setCurrency('GBP')"&gt;
  &lt;input type="button" value="EUR" OnClick="setCurrency('EUR')"&gt;
  &lt;input type="button" value="CAD" OnClick="setCurrency('CAD')"&gt;
  
  &lt;P&gt;Enter today's price of commodity in USD: &lt;input name="mktprc" input type="number"&gt;&lt;br&gt;&lt;p&gt;
  &lt;P&gt;Enter value of trade: &lt;input name="trdval" input type="number"&gt;
  
  &lt;input type="button" value="Calculate" OnClick="document.getElementById('showMeArea').value=finddivid(document.getElementById('mktprc'),document.getElementById('trdval')));"&gt;
  
  &lt;p&gt;
  &lt;br&gt;&lt;br&gt;
  
  &lt;input name="showMeArea" readonly="true" size="100"&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <hr>
  
  <p>If you run this html in your browser you should see what I am trying to achieve.</p>
  
  <p>I've tried for a while to get this to work and I don't know if the error if in the function or it the way I am trying to get the 'return' of the function 'finddivid' into the text box 'showMeArea'... </p>
  
  <p>Here are the main problems/features that I need help with:</p>
  
  <ol>
  <li>I would like to be able to click on one of the 'currency' buttons so that upon clicking, the variable 'currency' is assigned and then used in the function finddivid.</li>
  </ol>
  
  <p>(2. This isn't as important right now, but eventually, once this is working, I'd like it so that upon clicking one of the currency buttons, it changes colour, or is highlighted or something so that the user knows which currency rate they are using.)</p>
  
  <ol>
  <li>Upon entering the numbers into the two boxes I would like to click 'Calculate' and have it return what I've written in the function into the 'showMeArea' read-only box at the end of the code.</li>
  </ol>
  
  <p>I know I'm probably missing loads of stuff and I might be miles away from success but I am very new to programming (started just a few days ago!) so would like any kind of help that can be offered.</p>
  
  <p>Thanks in advance of your comments.</p>