0

I want to use this function to work on all my drop down lists. Problem: the first drop down works okay, but hen I try select any option in the 2nd drop down selections. It places the value from the first group in the span of the second group. I want the span to have the value from its own group. I would like to use this on multiple groups.

  <script>function displayResult(xspan,xselect)
{
 var x=document.getElementById(xselect).selectedIndex;
 alert(x);
 var newTxt = document.getElementsByTagName("option")[x].value;

 document.getElementById(xspan).innerHTML = newTxt;
 //alert(document.getElementsByTagName("option").length);
}
</script>

<select id="myPhones" onchange="displayResult('ShowPhone','myPhones')">
    <option value="">Phone  Numbers</option>
    <optgroup label="Shipping">
        <option value=" - 800-463-3339">FedEx</option>
        <option value=""></option>
    </optgroup>
</select>
<span id="ShowPhone"></span>

<select id="myParts" onchange="displayResult('ShowParts','myParts')">
    <option value="">Qik Parts list</option>
    <optgroup label="BATT">
        <option value="1">1</option>
        <option value="2">1</option>
        <option value="2">1</option>
        <option value="2"><1/option>
    </optgroup>
</select>
<span id="ShowParts"></span>
2
  • Can you show us the code for displayResult() ? Commented Nov 29, 2013 at 18:43
  • Where is the fracking displayResult function? Are we supposed to guess what it contains, or just create a new one for you without even knowing what it does ? Commented Nov 29, 2013 at 18:43

1 Answer 1

1

Chage the id and the displayResult of the second dropdown:

First dropdown:

<select id="myPhones" onchange="displayResult('ShowPhone','myPhones')">

Second dropdown:

<select id="NewNameID" onchange="displayResult('ShowPhone','NewNameID')">
Sign up to request clarification or add additional context in comments.

Comments

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.