Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript with buttons
    primarykey
    data
    text
    <p>I am creating a unit conversion program. I have everything working except for my calculate function and where the answer is being displayed. All i need help on is how to calculate each other the conversions, and to display the answer in a empty textbox that is below the calculate button. here is my code. </p> <pre class="lang-js prettyprint-override"><code>function showSecond() { if (document.getElementsByTagName("input")[0].checked){ div1.style.display = "block"; div.style.display = "none"; div2.style.display = "none"; } else if (document.getElementsByTagName("input")[1].checked){ div1.style.display = "none"; div.style.display = "block"; div2.style.display = "none"; } else { div1.style.display = "none"; div.style.display = "none"; div2.style.display = "block"; } } function Calc() { var amt = document.getElementsByName(amount) var res = document.getelementsByName(fin) if (document.getElementsByName("rad2")[0].checked) { var ch = amt * 2.2; document.write(fin) = ch; } else { res = amt / 2.2; document.write(res) } </code></pre> <pre class="lang-html prettyprint-override"><code>Select Conversion Type: &lt;br /&gt; &lt;input type = "radio" name = "rad1" onclick= "showSecond()" /&gt;Length &lt;br /&gt; &lt;input type = "radio" name = "rad1" onclick = "showSecond()" /&gt;Weight &lt;br /&gt; &lt;input type = "radio" name = "rad1" onclick = "showSecond()" /&gt;Volume &lt;br /&gt; &lt;div id = "div" style="display:none"&gt; Select Direction: &lt;br /&gt; &lt;input type = "radio" name = "rad2" value="PG" /&gt;Pounds to Kgs &lt;br /&gt; &lt;input type = "radio" name = "rad2" value="KP" /&gt;Kgs to Pounds &lt;br /&gt; Number to be converted: &lt;input type = "text" name = "amount" /&gt; &lt;br /&gt; &lt;input type = "button" value = "calculate" onclick = "Calc()" /&gt; &lt;br /&gt; &lt;input type ="text" name ="fin" value="" readonly="readonly"/&gt; &lt;/div&gt; &lt;div id = "div1" style="display:none"&gt; Select Direction: &lt;br /&gt; &lt;input type = "radio" name = "rad3" value="FM" /&gt;Feet to meters &lt;br /&gt; &lt;input type = "radio" name = "rad3" value="MF" /&gt;Meters to Feet &lt;br /&gt; Number to be converted: &lt;input type = "text" name = "amount" value=""/&gt; &lt;br /&gt; &lt;input type = "button" value = "calculate" onclick = "Calc()" /&gt; &lt;br /&gt; Result: &lt;br /&gt; &lt;input type="text" name ="fin" value ="" readonly="readonly"/&gt; &lt;/div&gt; &lt;div id = "div2" style="display:none"&gt; Select Direction: &lt;br /&gt; &lt;input type = "radio" name = "rad4" value="GL" /&gt;Gallons to Liters &lt;br /&gt; &lt;input type = "radio" name = "rad4" value="LG" /&gt;Liters to Gallons &lt;br /&gt; Number to be converted: &lt;input type = "text" name = "amount" /&gt; &lt;br /&gt; &lt;input type = "button" value = "calculate" onclick = "Calc()"&gt; &lt;br /&gt; Result: &lt;br /&gt; &lt;input type ="text" name = "fin" value="" readonly="readonly"/&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload