-1

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

omdx
  • 53
  • 7
  • You can do that with Javascript or with jQuery for more convenience. – aborted Jun 22 '16 at 14:09
  • php via postback? javascript? should some other action be taken for any of the other options? What have you tried? This question is currently too vague to answer, please edit to eloborate – Steve Jun 22 '16 at 14:09
  • Possible duplicate of [Get selected value in dropdown list using JavaScript?](http://stackoverflow.com/questions/1085801/get-selected-value-in-dropdown-list-using-javascript) – Madhawa Priyashantha Jun 22 '16 at 14:09
  • 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 – omdx Jun 23 '16 at 03:40

2 Answers2

0

if php you can get this post request

if($_POST['JnsDaftar'] == 'www.google.com') {
   header('Location:www.google.com');die;
}

if js you can get this value look comment Fast Snail and this Get selected value in dropdown list using JavaScript? link for get how to and adding just if

<script>
 // code for get value
 if($value == 'www.google.com') {
   window.location.href = 'www.google.com'
 }
</script>
Community
  • 1
  • 1
Naumov
  • 1,167
  • 9
  • 22
  • no. i don't want make redirect it's by post request. but if I select '2 - google.com', it live redirect to new page. – omdx Jun 23 '16 at 03:23
0

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";

}); });

omdx
  • 53
  • 7