0

I have a global select box on the page that I want to use to set all of the other select boxes on the page. They all have the same options in them.

So when I change the global drop down, how do I set all of the other ones to the same value.

All of my other select boxes have an id that starts with "inventory_location_select_"

$("#global_location").change(function(){ var globalValue = $("#global_location").val(); $("input[id^=inventory_location_select_]").val(globalValue); }); 

Here is my html:

Main Select Box:

<select id="global_location"> <option selected="selected">Choose Option</option> <option value="3542">Acme Pos 1</option> <option value="3545">Acme Pos 2</option> <option value="4892">Acme Test 1234567890</option> <option value="4896">FBA CA Prep</option> <option value="4889">FBA Prep 1</option> <option value="4895">FBA Prep 2</option> <option value="4897">FBA Prep 3</option> <option value="4893">POD 3 Area 1</option> </select> 

One of my other boxes:

<select id="inventory_location_select_1"> <option>Choose Option</option> <option value="3542">Acme Pos 1</option> <option value="3545">Acme Pos 2</option> <option value="4892">Acme Test 1234567890</option> <option value="4896">FBA CA Prep</option> <option value="4889">FBA Prep 1</option> <option value="4895">FBA Prep 2</option> <option value="4897">FBA Prep 3</option> <option value="4893">POD 3 Area 1</option> </select> 

This seems so easy, I just cant figure it out.

1
  • 1
    I dont. For example: inventory_location_select_1, inventory_location_select_2, inventory_location_select_3... etc. Commented Jan 30, 2014 at 17:47

2 Answers 2

1

The selector is wrong, you are trying to select input elements:

$("select[id^=inventory_location_select_]").val(globalValue); 
Sign up to request clarification or add additional context in comments.

2 Comments

Why is it always the dumbest things that make for the biggest hassles. Thanks so much, you're awesome!
@LargeTuna Yeah :) I think you had focused on the attribute selector part. This happens to best of us, we sometimes focus on the more complicated parts and miss the trivial ones. You are welcome!
1

Change:

$("input[id^=inventory_location_select_]").val(globalValue); 

to

$("[id^=inventory_location_select_]").val(globalValue); 

Your elements are selects, but you tried to change inputs. Either way you don't need to necessarily specify them. If you need to, use $("select[id^=inventory_location_select_]").val(globalValue);

jsFiddle example

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.