Is it possible to redirect a page and send a value from a field at the same time in jQuery?

Asked

Viewed 53 times

1

I needed to get a value from a clicked select option and send it to another page, only I would like to be redirecting to that same page. I am using jQuery mobile library, below follows my code in jQuery and the option:

<script> 
$(document).ready(function(){ 
        $("#select-native-fc").change(function(){ 
        var val = $("#select-native-fc").val(); 
        if($(".assy") && val == "1"){
            //alert("teste");
            window.location="time1.php";
        }
    }); 
}); 
</script>

</head>

<body>
<center>
<label for="slider2"></label>
<select name="slider2" id="slider2" data-role="slider">
  <option value="pkg">PKG</option>
  <option value="assy">ASSY</option>
</select>
</center>
<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="">Selecione</option>
        <option value="1">Assembly 1</option>
        <option value="2">Assembly 2</option>       
        <option value="3">Assembly 3</option>
        <option value="4">Assembly 4</option>
        <option value="5">Assembly 5</option>
        <option value="6">Assembly 6</option>
        <option value="7">Assembly 7</option>
        <option value="8">Assembly 8</option>
        <option value="9">Assembly 9</option>
        <option value="10">Assembly 10</option>
        <option value="X">Assembly X</option>
        <option value="Y">Assembly Y</option>
        <option value="Z">Assembly Z</option>

    </select>
</div>



<div class="ui-field-contain">  
    <label for="select-native-fc">Linhas de Packing:</label>
    <select name="select-native-fc" id="select-native-fc" class="pkg">
        <option value="">Selecione</option>
        <option value="1">Packing 1</option>
        <option value="2">Packing 2</option>
        <option value="3">Packing 3</option>
        <option value="4">Packing 4</option>
        <option value="5">Packing 5</option>
        <option value="6">Packing 6</option>
        <option value="7">Packing 7</option>
        <option value="8">Packing 8</option>
        <option value="9">Packing 9</option>
        <option value="10">Packing 10</option>
        <option value="X">Packing X</option>
        <option value="Y">Packing Y</option>
        <option value="Z">Packing Z</option>
    </select>   
</div>

My idea is that one click on an option and be redirected to another page. Until then beauty, is working.

But in the other page that I’m redirecting has a query, for example:

select * from tabela where linha = 'valor do option da outra pagina';

ie if the person chooses assembly1 with value 1 the query would look like this:

select * from tabela where linha = '1';

if the person chooses 2

select * from tabela where linha = '2';

that value would play in a variable $linha = $_POST['select-native-fc'];

The problem is I’m not using form. I know the other option is ajax, but I am beginner in ajax and would like to know if it is possible to do this without form.

  • Hello Daniel welcome to Stackoverflow, it is interesting to read the tour to know how the rules work on the site. http://answall.com/tour

  • You can pass the redirect address: window.location="time1.php?select-native-fc=" + val in PHP you will receive, $_GET['select-native-fc']

  • 1

    leandro valeu worked out

1 answer

1

Just add the value to the redirect url:

$(document).ready(function(){ 
    $("#select-native-fc").change(function(){ 
        var val = $("#select-native-fc").val(); 
        if($(".assy") && val == "1"){
            //alert("teste");
            window.location="time1.php?select-native-fc=" + val;
        }
    }); 
});

And in PHP you recover this value by making your query in the database.

Browser other questions tagged

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