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

1

I needed to get a value from a clicked option and send it to another page, but I would like to be redirecting to that same page. I'm using jQuery from the mobile library, below is 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 the person clicks on an option and is redirected to another page. Goodness, it's working.

But on the other page that I'm redirecting to, you have a query, for example:

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

That is, 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';

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

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

    
asked by anonymous 24.06.2016 / 19:40

1 answer

1

Just add the value in the url of the redirect:

$(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 retrieve this value by doing your query in the database.

    
03.08.2016 / 21:02