ainoy31 Posted December 3, 2007 Share Posted December 3, 2007 Hello- Scenario: I have two input fields with two radio buttons. The buttons will either convert the metric from lbs to kgs or stays as kgs base on what button is selected. It is not converting from lbs -> kgs or stays as kgs. Here is my code: First is the input field: <tr> <td>Actual Weight:</td> <td><input type="text" name="lbs" id="lbs" size="5"> <input type="radio" name="lbs" id="lbs" onClick="convert(); ">Lbs <input type="radio" name="kgs" id="kgs" onClick="convert(); ">Kgs = <input type="text" name="result" id="result" size="5">Kgs </td> </tr> My Javascript to convert: $(document).ready(function() { $('input.len, input.wid, input.hei, input.sum, input.lbs, input.kgs, input.sum1, input.sum2').keyup(function() { convert() }); }); function convert() { var kg = document.getElementById('kgs').value; var pounds = document.getElementById('lbs').value; if(kg == 0) { var result = pounds / 2.2;//gives the kgs from lbs } else { var result = kg; } sum_result(result); } function sum_result(result) { document.getElementById('result').value = result; } I have tried if(kg == null or kg == '') and no luck. I am probably overseeing it. Much appreciation. AM Quote Link to comment Share on other sites More sharing options...
phpQuestioner Posted December 3, 2007 Share Posted December 3, 2007 try this: <script language="javascript"> function convertUS() { var lbsvalue = document.getElementById('amount').value; document.getElementById('result').value=""+lbsvalue+""; if (lbsvalue.length < 1) { document.getElementById('result').value="0"; } document.getElementById('measurement').innerHTML=" Lbs"; } function convertNonUS() { var nonusameasure = document.getElementById('weight2').value; var lbsvalue = document.getElementById('amount').value; document.getElementById("result").value = lbsvalue / 2.2; document.getElementById('measurement').innerHTML=" Kgs"; } </script> <table> <tr> <td>Actual Weight:</td> <td><input type="text" name="lbs" id="amount" size="5"> <input type="radio" name="weight" value="lbs" id="weight" onClick="convertUS(); ">Lbs <input type="radio" name="weight2" value="kgs" id="weight2" onClick="convertNonUS(); ">Kgs = <input type="text" name="result" id="result" size="5"><span id="measurement"></span> </td> </tr> </table> Quote Link to comment Share on other sites More sharing options...
ainoy31 Posted December 4, 2007 Author Share Posted December 4, 2007 Thank you for helping out. Able to integrate your code and mine. It is working. Later. AM Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.