How do I redirect a page by clicking an option from a select by google Chrome?

Asked

Viewed 179 times

3

I am using this jquery already tried to use change also but does not run

<script>
$(document).ready(function(){
    $("#select-native-fc").on('click', function(){
            if($("#select-native-fc").val() == "ASM2")
            {
                alert('Teste');
            }
});
</script>

Select code:

<div class="ui-field-contain">  
    <label for="select-native-fc">Linhas de Assembly:</label>
    <select name="select-native-fc" id="select-native-fc" class="assy">
        <option value="http://www.youtube.com">Assembly 1</option>
        <option value="ASM2">Assembly 2</option>        
        <option value="ASM3">Assembly 3</option>
        <option value="ASM4">Assembly 4</option>
        <option value="ASM5">Assembly 5</option>
        <option value="ASM6">Assembly 6</option>
        <option value="ASM7">Assembly 7</option>
        <option value="ASM8">Assembly 8</option>
        <option value="ASM9">Assembly 9</option>
        <option value="ASM10">Assembly 10</option>
        <option value="ASMX">Assembly X</option>
        <option value="ASMY">Assembly Y</option>
        <option value="ASMZ">Assembly Z</option>

    </select>
</div>

I needed that by clicking on some option redirects to another page I am using jquery for mobile events only works for IE but in google Chrome does not work and even for mobile platform I am using these libraries of jquery below:

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
  • The action must be taken in the onChange and not in the onClick

  • Forehead .on('change',, as @rray suggested.

  • I tried not to

  • Didn’t work out you mean what? didn’t display the Alert?

  • yes does not perform anything already tried to do right up in select onChange="Alert('test');"

  • You tried to use .assy instead of #select-native-fc debug?

  • tried as well and it didn’t work out as close as I could in jquery was with onclick only it runs Alert in direct select or even open the checkbox

  • Then use <script>&#xA;$(document).ready(function(){&#xA; &#xA;&#xA;$("#select-native-fc").change(function(){&#xA; var val = $("#select-native-fc").val();&#xA; alert(val);&#xA; //your code&#xA;});&#xA;});&#xA;&#xA;</script> will work.

  • nothing should still be anything in the library

  • Depending on the library you should use the .live rather than .change or .on

  • I made a fiddle here. https://jsfiddle.net/oeo267j4/

  • you didn’t forget to close $(Document) didn’t?? I saw a "});" so the code checks error and doesn’t execute

Show 7 more comments

2 answers

3

Problem was that the ready was not closed, code fixed:

$(document).ready(function(){
    $("#select-native-fc").on('click', function(){
            if($("#select-native-fc").val() == "ASM2")
            {
                alert('Teste');
            }
    });
});

inserir a descrição da imagem aqui

2

Hum.. Code almost certain is missing close }) and use prevent $("#select-native-fc").trigger("click");

$(document).ready(function(){
    $("#select-native-fc").on('click', function(){
      if($("#select-native-fc").val() == "ASM2") {
        alert('Teste');
      }
    });
    $("#select-native-fc").trigger("click");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" rel="stylesheet"/>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
<div class="ui-field-contain">  
    <label for="select-native-fc">Linhas de Assembly:</label>
    <select name="select-native-fc" id="select-native-fc" class="assy">
        <option value="http://www.youtube.com">Assembly 1</option>
        <option value="ASM2">Assembly 2</option>        
        <option value="ASM3">Assembly 3</option>
        <option value="ASM4">Assembly 4</option>
        <option value="ASM5">Assembly 5</option>
        <option value="ASM6">Assembly 6</option>
        <option value="ASM7">Assembly 7</option>
        <option value="ASM8">Assembly 8</option>
        <option value="ASM9">Assembly 9</option>
        <option value="ASM10">Assembly 10</option>
        <option value="ASMX">Assembly X</option>
        <option value="ASMY">Assembly Y</option>
        <option value="ASMZ">Assembly Z</option>
    </select>
</div>

Here rotated beautiful and someone did not rotate, I can modify different more haddle specific code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.