Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2012
    Posts
    112
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Output Label instead of Value

    Hi Everyone

    The code that I am working on is here: http://www.payitforwardfriends.com/converter.html

    I'm trying to make it so that in the output when you convert from one substance to another it says what you are converting from (as in it says 1 cup of flour).

    The problem is "substance" is for the value, and not for the label. How do I make the label show up instead?

    Currently, it's coming up as [object HTMLSelectElement].

    Thanks so much!

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Same way it is done for the other <select>s.

    Look at them:
    Code:
    var inunittext = inunit.options[inunit.selectedIndex].text;
    var outunittext = outunit.options[outunit.selectedIndex].text;
    var densunittext = densunit.options[densunit.selectedIndex].text;
    So
    Code:
    var substance = document.getElementById("substance");
    var substanceAsText = substance.options[substance.selectedIndex].text;
    I used substanceAsText because you already have a variable named substanceText used for another purpose.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    112
    Thanks
    6
    Thanked 0 Times in 0 Posts
    That works. Thanks!


  •  

    Tags for this Thread

    Posting Permissions

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