Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Luis Magaña
Luis Magaña
13,042 Points

Need help opening up the 2 option values when user clicks on button.

Need help opening up the 2 option values when user clicks on button. Right now its opening the windows as soon as you make a change on dropdown select option but I want it to open when user clicks button. Any insight appreciated.

          <legend><span class="number">1</span>Select a Brand</legend>
          <label for="Brand">Brand:</label>
          <select id="brandSelect" name="brand_select">
            <optgroup label="Grills">
              <option value="http://site1.com">DCS</option>
              <option value="http://breezestafurniture.com http://dcsgrills.com">Alfresco</option>
              <option value="http://brandster.com/media/brandster2form/index.html http://coyoteoutdoor.com">Coyote</option>

        <button id="packageButton"type="submit">Sign Up</button>

       <script type="text/javascript">
       var urlmenu = document.getElementById( 'brandSelect' );
       var btn = document.getElementById('packageButton');
       urlmenu.onchange = function() {
          var urls = this.options[ this.selectedIndex ].value.split(' ');
          urls.forEach( function(url) {

2 Answers

Erik Krieg
Erik Krieg
43,038 Points

If I understand correctly, you want the new page to open when a user clicks the submit button, instead of when they select an option.

In that case, what you want to do is listen to a click on the submit button instead of onchange for the select field. Use that event to trigger your callback function and I think you will have your desired result.

I created a little demo of this behavior for you in this codepen.

Hope that helps! ♥

Luis Magaña
Luis Magaña
13,042 Points

Erik Krieg wow this worked for me thanks alot I was assuming .onClick handled that if I added it to a variable like btn.onClick, now Im trying to figure out why Magento is opening up the url values twice but this is a start, thanks alot.