pass values from the checkbox to the url

0

Good afternoon, I have a question on how to move the selected items from a page to a URL to issue a report, the whole code is working fine, but that part is missing.

example

item     codigo
1        11
2        12
3        13
4        14
5        15

How do I select the checkbox of items 1,2,5 to be passed through a url as follows: www.teste.com/realatorio.php?id=1,2,5

<?php
                while ($row = mysql_fetch_object($saldo_financeiro2)) {
                    $cliente = $row->nome_cliente;/* dentro do $row[] vai o nome da coluna da sua consulta */
                    echo '<tr>
                    <td>
                        <input class="input-field" type="checkbox" name="age" value="'.$row->item.'"/>
                        <label></label>
                    </td>';
                    echo "<td>".date('d-m-Y', strtotime($row->codigo))."</td>
                    </tr>";
                }
                ?>

    
asked by anonymous 15.06.2016 / 21:07

3 answers

1

You can do something like this

<input type="checkbox" name="age" <?php if (isset($age) && $age=="1") echo "checked";?> value="1">1-9
<input type="checkbox" name="age" <?php if (isset($age) && $age=="10") echo "checked";?> value="10">10-19
<input type="checkbox" name="age" <?php if (isset($age) && $age=="20") echo "checked";?> value="20">20-29
<input type="checkbox" name="age" <?php if (isset($age) && $age=="30") echo "checked";?> value="30">30-39

Server-side receives as a $ _POST ['age']

 $ages = $_POST['age'];
 print($ages[0]);
    
15.06.2016 / 21:19
0

window.history.pushState (data, null, 'url_alvo');

You will have to do a function, for example, with jquery.

$('checkbox').on('click', function(){
   window.history.pushState(null,null,'index.php?id'+$(this).val());
});

NOTE: This is an HTML5 feature, depending on which broswer might not work.

    
15.06.2016 / 21:16
0

How do I select the checkbox for items 1,2,5 to be passed through a url as follows: www.teste.com/realatorio.php?id=1,2,5.
This was your question my answer, created just your url example which is www.teste.com/realatorio.php?id=1,2,5.

In HTML you create the inputs I created this class to guide what is happening

<input type="checkbox" valor="1">
<input type="checkbox" valor="2">
<input type="checkbox" valor="3">
<input type="checkbox" valor="4">
<p class="url"></p>

In Jquery you create your URL

jQuery(function($) {
    // www.teste.com/realatorio.php?id=1,2,5
    var url = Array();
    $('input[type="checkbox"]').change(function(){
        if($(this).is(':checked')){
            url.push($(this).attr('valor'));
        }else{
            url.pop($(this).attr('valor'));
        }
        var terminar = url.toString();
        $('#url').html('<p>www.teste.com/realatorio.php?id='+terminar+'</p>');
    })
})

In the example you will create a url similar to what you want
"www.teste.com/realatorio.php?id=1,2,5", marking the inputs checked will carry the values. I hope it helped you.

This is an example of how you can make your url.

    
15.06.2016 / 21:57