1
<center>
    <h3> A </h3>
    <h4> vs </h4>
    <h3> B </h3>
    <h4> 60 - 70 </h4>
</center>

<div class="12u$">
    <div class="select-wrapper">
        <select name="teamA" id="A" style="max-width:30%;">
            <option value="">- TeamA -</option>
            <option value="1">Kansas</option>
            <option value="1">Oklahoma</option>
            <option value="1">Texas</option>
            <option value="1">Notre Dame</option>
        </select>
    </div>
</div>
<div class="12u$">
    <div class="select-wrapper">
        <select name="teamB" id="B" style="max-width:30%;">
            <option value="">- TeamB -</option>
            <option value="1">Kansas</option>
            <option value="1">Oklahoma</option>
            <option value="1">Texas</option>
            <option value="1">Notre Dame</option>
        </select>
    </div>
</div>
<script>
    $("select")
        .change(function() {
            var str = "Team A";
            $("select option:selected").each(function() {
                str = $(this).text() + " ";
            });
            $("h3").text(str);
        })
        .change();
</script>

This will work for one selector but how do I make another script that changes a separate select.

10
  • What do you mean by changes a separate select?? Commented Mar 11, 2016 at 8:22
  • You have an extra < in your code before the <script> tag Commented Mar 11, 2016 at 8:38
  • So I have two selects and I want them to change two different texts, however this script can only point to one select currently. I have made another select and how to do I change the script so I can change them independently? Commented Mar 11, 2016 at 8:39
  • So based on the value of the option selected in the first dropdown, you want to change the value of the second dropdown to something? Commented Mar 11, 2016 at 8:40
  • The last .change() seems unnecessary. Commented Mar 11, 2016 at 8:40

2 Answers 2

1

You can use the ID of your selects, (btw, id A and B are a bit.. short..)

$("#A").change();
$("#B").change();

Or check what ID the select has:

$("select").change(function(){
    if(this.id == "A")
    {
        // Its the first one that changed
    }
    else if(this.id == "B")
    {
        // Its the second one that changed
    }
});
Sign up to request clarification or add additional context in comments.

Comments

1

If the headers have id's that correspond to the select's id, you can use the select's id to obtain the corresponding headers. e.g. with header ids 'hA' and 'hB':

$( "select" ).change(function () {
    $('#h' + this.id).text(this.options[this.selectedIndex].text);
});

Fiddle

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.