0

I have first a with 3 option value in it. When I select one of the values, I want it to remember which one I picked and once I press my button the javascript will open a specific url.

Some code sample.

       <select id="dd-files">
        <option value="asdf">Pick:</option>
        <option value="url1">File1</option>
        <option value="url2">File2</option>
        <option value="url3">File3</option>
       </select>
      </section>
    </div>
<br>
        <div class="modal-footer">
            <a class="btn btn-primary get-data" href="#">Button</a>
        </div>

javascript This javascript directily just to know how it all works, so I just tested it.

$(".get-data").on("click",function() {
  var location = 'http://hardcodedurl.com';
  window.open(location);

Then I have another function, which when I pick one option value, stores it and open it directly, but instead of open it directly, I would like my second script just to open when my button ".get-data" is pressed.

$(function () {
  $('#dd-files').on('change', function() {
    debugger;
    var url = $(this).val();
    if (url) {
      window.location = url;
    }
    return false;
  })
})

Any advice for a newbie?

2
  • 3
    Do they call you the HTML Slasher? Commented Jan 29, 2013 at 7:55
  • The html \ is because its written in js, so for it to read next line, im using \ otherwise it crashes you know :-) Commented Jan 30, 2013 at 9:57

1 Answer 1

1

Not clear why do you need on('change') event. To make it open when button is pressed, you just need something like this:

$(".get-data").on("click",function() {
  var location = $('#dd-files').val(); 
  if(location) {
     window.open(location);
  }
}

Just take an url from #dd-files directly.

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

2 Comments

Oh thank you! That worked just fine, dont ask me what I was thinking there for a second. By the way, if this is placed in a form, which is generated by pressing a <li> children one step ahead. Like this <li><a id='stoparea' data-name='data-value' href='#'>firstpicked</a></li>" Is it possible to have it look on first which option I picked one step ahead and then store next one?
Frankly speaking it is not clear to me what are you talking about. Once you have few elements - just build a selector which will get an element you need, take its value and do whatever you need with it.

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.