SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Mar 2014
    Location
    Sanandaj
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with addEventListener

    Hi guys. I'm new to JavaScript.
    I want to see the result of the below textbox as the user insert a number into the text box and it should change the currency when user select new currency.
    Here's my code:

    Code:
    window.addEventListener('load', fireUp, false);
    
    function fireUp () {
        if ( document.getElementById('number') ) { //If brwoser support JavaScript
            var cost = document.getElementById('number').addEventListener('keydown', showResult, false);
            var currency = document.getElementById('currency').addEventListener('change', showCurrency, false);
    
            if ( cost && currency ) {
                var newCost = document.createTextNode(currency + cost);
                document.getElementById('result').appendChild(newcost);
            }
        }
    }
    
    function showResult (evt) {
        var insertedNumber = evt.target;
        return insertedNumber.value;
    }
    
    function showCurrency (evt) {
        var insertedCurrency = evt.target.options[evt.target.selectedIndex];
        return insertedCurrency.text;
    }

    I don't know why my functions don't return the result when I call them by addEvenetListener.

  2. #2
    SitePoint Addict
    Join Date
    Jan 2009
    Posts
    369
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hamm, can you post your html as well


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •