0

Sending the value of the select option is not working but I am able to get the value and print it, so it's definitely the $.get.

$(document).ready(function () {    
//hover method to drop down nav menu
.
.
.
.

$('select').change( function() {
    var val = $('#sortOpt').val();
    $.get(
        "http://localhost/e-com/index.php/products/categories?cat=cameras&",
        {
            sort: val
        },
        function(data){}
    )
});
});
2
  • 1
    What does arrive at the server? See access log or better look into the network tab of your JavaScript debugger to see what the get method sends. Commented Mar 8, 2014 at 17:10
  • It was sending nothing, but it's working now. I got this code from this site and I didn't know what function(data){} was, so removing it worked. Commented Mar 9, 2014 at 14:13

2 Answers 2

1

You need to fix the following :

   var val = $('#sortOpt').val();
//^remove the '$'

You've also got an extra } at the end of your $.get() call.

Once fixed, you should have:

$('select').change( function() {
    var val = $('#sortOpt').val();
    $.get(
        "http://localhost/e-com/index.php/products/categories?cat=cameras&",
        {
            sort: val
        },
        function(data){}
    );
});
Sign up to request clarification or add additional context in comments.

4 Comments

the $ sign is a typo when I deleted a line before that and the extra { is for $(document).ready(function () {
Ok, what is the #sortOpt element? Are you getting the "cat" value?
#sortOpt is a select option, yes I am able to get the cat value.
Do you mean to get the current selection? You can use $(this).val() to do that instead.
0

You should send data as url parameters:

$.get(
    "http://localhost/e-com/index.php/products/categories?cat=cameras&sort=" + val,
    function(data){}
});

1 Comment

That's effectively what he's doing at the moment. See the documentation for the second parameter to get(). api.jquery.com/jQuery.get

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.