0

I want to display 3 different a text depending on the select. I already have a code where this works but it picks the "value" of the select and the value needs to be a text. As you will see that would not work for the code. Now im searching an alternative like picking the id or the name or whatever is possible. like instead of a.value a.id but this doesn't work.

maybe the solution is very obvious but have nearly 0 experience in JavaScript i only learned some C++ and HTML in school a few months ago and i just put some peaces of other codes together to create mine.

http://jsfiddle.net/qT5KX/8/

<select onChange="AA(this);BB(this);CC(this)">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>
<script type='text/javascript'>
    function AA(a) {
        a = a.value;
        b = document.getElementById("A");
        c= "A";
        d= c+a;
        e = document.getElementById(d);
        b.innerHTML = e.innerHTML;
    }
    function BB(a) {
        f = a.value;
        g = document.getElementById("B");
        h= "B";
        i= h+f;
        j = document.getElementById(i);
        g.innerHTML = j.innerHTML;
    }
    function CC(a) {
        k = a.value;
        l = document.getElementById("C");
        m= "C";
        n= m+k;
        o = document.getElementById(n);
        l.innerHTML = o.innerHTML;
    }</script>
<div id='A' style='display:'><h3>A1</h3></div>
<div id='A1' style='display:none'><h3>A1</h3></div>
<div id='A2' style='display:none'><h3>A2</h3></div>
<div id='A3' style='display:none'><h3>A3</h3></div>

<div id='B' style='display:'><h3>B1</h3></div>
<div id='B1' style='display:none'><h3>B1</h3></div>
<div id='B2' style='display:none'><h3>B2</h3></div>
<div id='B3' style='display:none'><h3>B3</h3></div>

<div id='C' style='display:'><h3>C1</h3></div>
<div id='C1' style='display:none'><h3>C1</h3></div>
<div id='C2' style='display:none'><h3>C2</h3></div>
<div id='C3' style='display:none'><h3>C3</h3></div>
realape
  • 33
  • 3
  • See first answer in http://stackoverflow.com/questions/4641962/getting-an-option-text-value-with-javascript for an example of what you are trying to do. – E. Valencia Apr 30 '14 at 10:12
  • Thank you it does work now http://jsfiddle.net/qT5KX/18/ – realape Apr 30 '14 at 11:32

0 Answers0