1

I have a selection list:

<select class="inputbox" onchange="document.location.replace(this.value);" >
    <option dir="ltr" value="/nl" >Nederlands (NL)</option>
    <option dir="ltr" value="/de" >Deutsch (DE)</option>
    <option dir="ltr" value="/en/orange" selected="selected">English (UK)</option>
</select>

And I need the the content from this span...

<dd class="category-name">Category: <span itemprop="genre">Orange</span></dd>

to be added (including slash) to all values except the selected one. So that the result will be:

<select class="inputbox" onchange="document.location.replace(this.value);" >
    <option dir="ltr" value="/nl/orange" >Nederlands (NL)</option>
    <option dir="ltr" value="/de/orange" >Deutsch (DE)</option>
    <option dir="ltr" value="/en/orange" selected="selected">English (UK)</option>
</select>
2
  • 1
    Can you please provide the code you have attempted? Commented Nov 11, 2014 at 10:17
  • You want to add "orange" to the first two options /nl and /de? Commented Nov 11, 2014 at 10:20

1 Answer 1

1

You can use .val() like

var itemprop = $('.category-name span').text().toLowerCase().trim();
$('select.inputbox option:not(:selected)').val(function(i, text) {
  return text + '/' + itemprop;
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<dd class="category-name">Category: <span itemprop="genre">Orange</span></dd>
<select class="inputbox" onchange="document.location.replace(this.value);">
  <option dir="ltr" value="/nl">Nederlands (NL)</option>
  <option dir="ltr" value="/de">Deutsch (DE)</option>
  <option dir="ltr" value="/en/orange" selected="selected">English (UK)</option>
</select>

Sign up to request clarification or add additional context in comments.

2 Comments

In another scenario I would like to just get the 'category' from the selected option (in this case '/orange') and append to the other values (i.e. /nl/orange). Is that possible?
When the selected url contains more elements after split (i.e. '/en/orange/blue') it will append the first element only (i.e. '/nl/orange). How to append all elements after split if exist?

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.