• 26-09-2013, 21:22:28
    #1
    Üyeliği durduruldu
    Herkese iyi akşamlar,

    Checkbox ile filtreleme yapmaya çalışıyorum.
    İşaretlenen değerleri bir dizi(session) ' de/da tutacağım.
    Fakat işaretlenen checkbox'ın değerini alamıyorum.

    Her işaretlemede sayfa post ediliyor.

    Örnekle göstereyim.
    [x] (İşaretli checkbox kutucugu), [] (İşaretsiz checkbox kutucugu)


    [x] Coca Cola (id =12)
    [x] Pepsi (id =13)
    [] Le Cola (id =14)
    [] Cola Turka (id =15)

    Le 'colayı işaretlediğimde , onclick=submit(), ile post ediyorum.
    Post değerinde Le Cola ile birlikte pepsi ve coca cola'nın değeri geliyor.
    Örnek (0=>'12',1=>'13',2=>'14') olarak geliyor.
    Fakat ben seçilen Le Cola'nın değerini almak istiyorum.

    Aynı şekilde checkbox'ı silineninde değerini almak istiyorum.(İşaretliyken işaretsiz hala getirdiğimde)


    Uzun zamandır uğraşıyorum, bir yardımcı olursanız sevinirim.
  • 26-09-2013, 22:18:33
    #2
    <?php
    // filename: test.php
    
    if (isset($_POST['cola']))
    {
        // Static class FirePHP from PEAR
        require 'FirePHPCore/fb.php';
    
        // DEBUG
        FB::info($_POST['cola']);
        
        /* Sample output
        array(
            'pepsi'        => 'on'
            'le_cola'    => 'on'
            'cola_turka'=> 'on'
        )
        */
    }
    ?>
    <!doctype html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Test</title>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>
            $(function(){
    
                $("#form input[type=checkbox]").click(function()
                {
                    $.post("test.php", $("#form").serialize());
                });
    
            });
        </script>
    </head>
    <body>
        
        <form action="post" id="form">
            <ul>
                <li><input type="checkbox" name="cola[coca_cola]"> Coca Cola</li>
                <li><input type="checkbox" name="cola[pepsi]"> Pepsi</li>
                <li><input type="checkbox" name="cola[le_cola]"> Le Cola</li>
                <li><input type="checkbox" name="cola[cola_turka]"> Cola Turka</li>
            </ul>
        </form>
        
    </body>
    </html>
  • 26-09-2013, 23:07:29
    #3
    Üyeliği durduruldu
    R10'dan bir arkadaş ile problemi GET ile çözdük.

    <script type="text/javascript">
    $('input[type=checkbox]').on('click', function() {
        var secilen = $(this).val();
        var x = $(this).attr('checked');
        
    if (x != 'checked') {
        window.location='index.php?r=site/markafiltre&kid=8&silinen='+secilen;
        
    } else {
        
        window.location='index.php?r=site/markafiltre&kid=8&secilen='+secilen;
    }
    });
    </script>
    Alexis, hocam post ile çözümünü yazmışsınız, sizede teşekkür ederim.