R
R
rusgayfer2018-03-02 13:41:40
JavaScript
rusgayfer, 2018-03-02 13:41:40

How to get data from select in url link?

How can I make the link change when the select is changed?

<div class="form-group">
<label class="col-lg-4 control-label" for="focusedInput">Выберите группу:
</label>
 <div class="col-lg-6">
<select class="form-control" id="taskOption_group" name="taskOption_group">
 <option value="0">- Не выбрано -</option>
<option value="79668981">Сообщество №1</option>
<option value="61439844">Сообщество №2</option>
<option value="66162914">Сообщество №3</option>
<option value="71359952">Сообщество №4</option>
<option value="96811414">Сообщество №5</option>
<option value="68946366">Сообщество №6</option>
</select>
</div>
</div>

So that when the choice changes the link. There can be many communities in a select.
<a href="https://vk.com/club{id}">Ссылка</a>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Skibin, 2018-03-02
@rusgayfer

$('#taskOption_group').on('change', function() {
  if ($(this).val() !== '0') {
    document.location.href = 'https://vk.com/club' + $(this).val();
  }
});

So ?

P
po5epT, 2018-03-02
@po5epT

On onchange, you take its value from the select and add it to the link.
Move the link to a variable so that you don't have to cut/replace the previous one each time.
After all, you insert the href attribute that you received earlier.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question