0

I want to forward the user to other pages by letting them choose the appropriate image. There is a problem when the user chooses two images. I don't know how to set forwarding when the user chooses these 2 images, any ideas? Here's the tool that I used %windir%\Temp folder . Thanks you guys for help!

 <html>
<head>
      <!-- scripts for imagepicker -->
    <link rel="stylesheet" href="assets/css/image-picker.css">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="assets/js/image-picker.js"></script>
    <script type="text/javascript">


        "use strict";
        //wait for the page to be fully loaded
        window.onload = function() {
            initialize();
        }
    </script>
    <title></title>
</head>
<body>
    <div class="container">
        <br> <br> <br> <br>
        <div class="jumbotron">

                    <!-- 2 obrazki -->

                    <div class="row">
          <div class="col-xs-6 col-md-3"></div>
          <center>
          <select multiple="multiple" class="image-picker show-html" id="selectImg">

          <div class="col-xs-6 col-md-3 flags container" >
            <option class="col-xs-6 col-md-3 flags" data-img-src="assets/media/img/german.png" value="1"></option>
          </div>

          <div class="col-xs-6 col-md-3 flags container" >
            <option class="col-xs-6 col-md-3 flags" data-img-src="assets/media/img/spain.png" value="2"></option>
          </div>

        </div>
        </select>
       </center> 
            <!-- 2 obrazki -->
              </div>
              <div class="form-group container">
                <center>
                    <p>Kliknij tu i <br><a id="forwardButton" class="btn btn-lg btn-success" type="submit" href="#" role="button">Dołącz do Poliglotów</a></p>
                </center>
              </div>
            </form>
        </div>
    </div>


    <!--SCRIPTS imgpickr DON'T TOUCH-->

  <script>

    $("select").imagepicker();
    function initialize() {

        var choice; //= document.getElementById("selectImg").value;


        //changes destination when you set or change your choice
        document.getElementById("selectImg").onchange = function() {

            choice = document.getElementById("selectImg").value;


        }
        //when button is clicked
        document.getElementById("forwardButton").onclick = function() {


            if(choice == 1){
              window.location = "https://www.google.com";
            }
            else if(choice == 2){
              window.location = "https://www.facebook.com";

            }
            else if(choice == 1 && choice == 2){
              window.location = "https://www.twitter.com";

            }

        } 
    }


  </script>




</body>
</html>
HavelTheGreat
  • 3,299
  • 2
  • 15
  • 34
tom
  • 165
  • 1
  • 2
  • 10

1 Answers1

0

Look at this example answered before: How to get all selected values of a multiple select box using JavaScript?

Community
  • 1
  • 1
Seti
  • 2,169
  • 16
  • 26