omdx omdx - 5 months ago 10
PHP Question

redirect page based select option (with dynamic value)

my selectbox:

<div>
<select name="JnsDaftar" id="JnsDaftar" required>
<option value="" disabled selected></option>
<option value="A">1 - A</option>
<option value="www.google.com">2 - google.com</option>
<option value="B">3 - B</option>
<option value="C">4 - C</option>
<option value="D">5 - D</option>
</select>
<label for="JnsDaftar">KARABO TANGKAL!</label>
</div>


N i want to redirect to google.com if I select option 2. Other Value not redirect.
Thx.

-- Edit --

I want to live redirect it to new page if I select option 2. Not via Post request. maybe javascript or Jquery. And the other option not redirect (the other option i want to save value by post request). thx

-- Edit --

Sample: JSFIDDLE

Answer

I Solved with this code:

$( document ).ready(function() {
$('#JnsDaftar').on("change", function(e){

  if($(this).val() == 'www.google.com'){

        swal({
        text: "Anda akan diarahkan pada laman PERBAIKAN BIODATA WNI!",
        type: "info",
        confirmButtonText: "OK"
        }).then(
        function(isConfirm){
        window.location.href = "ihttp://www.google.com";
        });
    }
  //window.location.url="www.google.com";

}); });