Need help witch small function...

Discussion in 'JavaScript' started by ignas2526, Jan 5, 2009.

  1. #1
    Hello,
    I trying to code script who will show tip depending on what is selected, but for unknown reason it does not work...
    Here is code:
    <script>
    function give_tip() {
    var sel = document.getElementById ('select').value;
    var tip = '';
    switch(sel){
    	case'First':
    		tip = 'First is selected.';
    	break;
    	case'Second':
    		tip = 'Second is selected.';
    	break;
    	case'Third':
    		tip = 'Third is selected.';
    	break;
    }
    document.getElementById ('tip').value = tip;
    }
    </script>
    <select id="select" onchange='give_tip()'>
    <option>First</option><option>Second</option><option>Third</option>
    </select>
    <div id='tip' style="border:1px; width:100px; height:100px; overflow:auto;">
    tip goes here...
    </div>
    Code (markup):
    Thanks.
     
    ignas2526, Jan 5, 2009 IP
  2. BLuka

    BLuka Active Member

    Messages:
    1,286
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    80
    #2
    Sorry, But I don't understand these stuff, what are you scripting?
     
    BLuka, Jan 5, 2009 IP
  3. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    O well,
    I figured out, the problem was in document.getElementById ('tip').value must be document.getElementById ('tip').innerHTML div does not like values =D.
    @BLuka, i was trying to show tip after visitor selected something from drop down list.
     
    ignas2526, Jan 5, 2009 IP
  4. phper

    phper Active Member

    Messages:
    247
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    innerHTML is not standard. For text elements, to change the text element in it, you do:
    document.getElementById('tip').firstChild.data = tip;
     
    phper, Jan 5, 2009 IP