Q:

use values from different select options in one function with jquery

i have two select options in my html,i want to calculate cost of travel between two cities, how will i get to compare the two select options selected by the user using jquery, here is the code iam working with now.
</head>
<body>
  <div>
    <select id="origin" name="form_select">
      <option value="" disabled selected> select cargo origin...</option>
      <option value="0">chicago</option>
      <option value="1">london</option>
      <option value="1">berlin</option>
    </select>
  </div>
  <div>
    <select id="destination" name="form_select">
      <option value="" disabled selected> select cargo destination...< /option>
      <option value="0">dubai</option>
      <option value="1">london</option>
      <option value="1">berlin</option>
    </select>
  </div>

and this is the bit of jquery code i have, right   now it only shows and hides div when an option is selected,i couldn't get how to call different values from different select options on the same function so as to calculate distance
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function(){
    $("#origin").change(function(){
      $(this).find("option:selected").each(function(){
        if($(this).attr("value")=="1"){
          $("#hidden_div").show();
        }else{
          $("#hidden_div").hide();
        }     
      });
    });

    $("#destination").change(function(){
      $(this).find("option:selected").each(function(){
        var my =$("#test" ).val();
        if($(this).attr("value")<="1"){
          var my = $( "#myselect option:selected" ).text();
          alert(my);
          $("#hidden_div").show();
        }else{
          $("#hidden_div").hide();
        }
      });
    });

  });
</script>

A:

First of all you may want to use the country name as those options' value
Second, you are duplicated the value of both the last & second last of option of origin and the destination
With jQuery, you could also use .val() to get the value on an input element, read more on http://api.jquery.com/val/
You could consider the following scripts to compare the destination:
function Compare(origin, destination) {
    if (origin.length > 0 && destination.length > 0) {
    if (origin == destination) alert("You have the same origin and destination!");
    else {
        $(".result").html("origin: " + origin + "<br />destination: " + destination);
        return true;
    }
  }
  return false
}

var $origin = $("#origin"),
        $destination = $("#destination");

$("#origin, #destination").change(function(){
    Compare($origin.val(), $destination.val());
});

You could try it on https://jsfiddle.net/m9ghaj41/

