Hello,

My HTML+JS :

<head>
        <script type="text/javascript">
                function passList() {
                        var p=[];
                        $('input.first').each( function() {
                                if($(this).attr('checked')) {
                                        p.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'process.php',
                                type:'POST',
                                data: {list:p},
                                success: function(res) {
                                $("#result").html(res);

                                }
                        });
                }

               function passType() {
                        var q=[];
                        $('input.second').each( function() {
                                if($(this).attr('checked')) {
                                        q.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'process.php',
                                type:'POST',
                                data: {type:q},
                                success: function(res) {
                                $("#result").html(res);

                                }
                        });
                }

        </script>
</head>
<body>
        <input type="checkbox" class="first" rel="list1" onclick="passList()">list1<br />
        <input type="checkbox" class="first" rel="list2" onclick="passList()">list2<br />
        <input type="checkbox" class="first" rel="list3" onclick="passList()">list3<br />
        <input type="checkbox" class="first" rel="list4" onclick="passList()">list4<br />
       <br><br><br>
    <input type="checkbox" class="second" rel="type1" onclick="passType()">type1<br />
        <input type="checkbox" class="second" rel="type2" onclick="passType()">type2<br />
        <input type="checkbox" class="second" rel="type3" onclick="passType()">type3<br />
        <br><br><br> 

        <div id="result"> </div>        
</body>

I am able to get the value in the div "result" thru the following script :

if(isset($_POST['list']) && !isset($_POST['type'])) {
     foreach ($_POST['list'] as $list) {
      echo "this is $list<br />"; 
      }
    }
    else if(!isset($_POST['list']) && isset($_POST['type'])) {
     foreach ($_POST['type'] as $type) {
      echo "type is : $type<br />"; 
     }
    }
    else if(isset($_POST['list']) && isset($_POST['type'])) {
     foreach ($_POST['list'] as $list) {
      echo "Showing ads for $list<br />"; 
       foreach ($_POST['type'] as $type) {
       echo "type is : $type<br />"; 
      }
     }
    }

But i get the value of either the list or the type.

I want to be able to get the value of both at the same time. I dont want to use a <form>.

Please help.

Thank you.

i think you want this.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script type="text/javascript">
                function passList() {
                        var p=[];
                        $('input.first').each( function() {
                                if($(this).prop('checked')) {                                      
                                        p.push($(this).attr('rel'));
                                }
                        } );

                        var q=[];
                        $('input.second').each( function() {

                                if($(this).prop('checked')) {

                                        q.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'process.php',
                                type:'POST',
                                data: {list:p,type:q},
                                success: function(res) {
                                $("#result").html(res);

                                }
                        });
                }

               /*function passType() {
                        var q=[];
                        $('input.second').each( function() {
                        q.push($(this).attr('rel'));
                                if($(this).attr('checked')) {
                                        q.push($(this).attr('rel'));
                                }
                        } );
                        $.ajax( {
                                url:'process.php',
                                type:'POST',
                                data: {type:q},
                                success: function(res) {
                                $("#result").html(res);

                                }
                        });
                }*/

        </script>
</head>
<body>
        <input type="checkbox" class="first" rel="list1" onclick="passList()">list1<br />
        <input type="checkbox" class="first" rel="list2" onclick="passList()">list2<br />
        <input type="checkbox" class="first" rel="list3" onclick="passList()">list3<br />
        <input type="checkbox" class="first" rel="list4" onclick="passList()">list4<br />
       <br><br><br>
    <input type="checkbox" class="second" rel="type1" onclick="passList()">type1<br />
        <input type="checkbox" class="second" rel="type2" onclick="passList()">type2<br />
        <input type="checkbox" class="second" rel="type3" onclick="passList()">type3<br />
        <br><br><br> 

        <div id="result"> </div>        
</body>
</html>

Dear MangelMurti .. thank you very much!

I am close to what i want.

Thanks a ton buddy !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.