1

Im using the folowing to search a database :

   <script type="text/javascript">
      $(function() {
        $("#lets_search").bind('submit',function() {
          var cat1 = $('#cat1').val();
           $.post('db.php',{cat1:cat1}, function(data){
             $("#search_results").html(data);
           });
           return false;
        });
      });
    </script>

cat1 is the id of a drop down box. I want to add another drop down box so that the query would be :

SELECT * 
  FROM business
  WHERE category='".$_POST['cat1']."' and subcategory='".$_POST['cat2']."'

I cant seem to get the javascript to work with more than one drop down. I have tried this , but it didnt work.

<script type="text/javascript">
  $(function() {
    $("#lets_search").bind('submit',function() {
      var cat1 = $('#cat1').val();
       var cat2 = $('#cat2').val();
       $.post('db.php',{cat1:cat1},{cat2:cat2}, function(data){
         $("#search_results").html(data);
       });
       return false;
    });
  });
</script>

2 Answers 2

2

You are constructing the data in wrong wya. Try with -

$.post('db.php',{cat1:cat1,cat2:cat2}, function(data){ ...
Sign up to request clarification or add additional context in comments.

4 Comments

Enough in comment also.No need of answer
Thanks. Ill make this the right answer when it lets me
@SunilPachlangia know that but according to - meta.stackoverflow.com/questions/271229/…. gave the answer.
Its just a question we should follow help center's guide line
0

You can rewrite your function in more secure way by serializing the form if you have multiple elements to send.

Blockquote $.post('db.php',$('#form').serialize(), function(data){ ...});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.