1

Here's a bit of code from a simple currency converter I'm building. The calculate() script runs fine, but the clear() code refuses to work and it appears the same??

<a href="#" OnCLick="calculate();">US - CDN</a>
<a href="#" OnCLick="clear();">Clear</a>

<script type="text/javascript">
    function clear() {
            document.getElementById('us-cdn1').innerHTML = '';
    }
</script>
<script type="text/javascript">
    function calculate() {
        var amount = parseFloat(document.getElementById("amount").value);
        var result = document.getElementById("amount");
            result.value = (amount).toFixed(2);
        var result = document.getElementById("amount1");
            result.value = (amount * .9861932938856016).toFixed(2); 
            document.getElementById('us-cdn').innerHTML = 'US';
            document.getElementById('us-cdn1').innerHTML = 'CDN';
    }

</script>
10
  • sorry, bad post... the tag was closed... The calculate script works fine... just the clear is failing Commented Feb 3, 2013 at 18:03
  • Never mind, I see your comment Commented Feb 3, 2013 at 18:04
  • btw... appreciate your quick answer... anything else look wrong there... I'm really scratching my head! Commented Feb 3, 2013 at 18:04
  • 1
    I recommend you use jQuery and add your listeners afterwards. Have a look at this fiddle Commented Feb 3, 2013 at 18:13
  • 1
    Here is a good explanation about clear() stackoverflow.com/questions/7165570/… Commented Feb 3, 2013 at 18:22

1 Answer 1

1

clear() is a public function. Change it into:

<a href="#" onclick="clearField();">Clear</a>

<script type="text/javascript">
function clearField() {
        document.getElementById('us-cdn1').innerHTML = '';
}
</script>
Sign up to request clarification or add additional context in comments.

1 Comment

+1 - Only as a note to be 100% accurate it's actually onclick, you can read about it here: onclick or onClick?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.