0

I have an HTML form and it contains basically of one input text box and one select...

Input box

echo '<input type="input" id="category_typex" name="category_typex" value="" />';

Select

echo '<select name="primary_cat" id="primary_cat" onChange="getSecondaryCat(this.value);">';

The Ajax code I'm using to pass the select is as follows:

function getSecondaryCat(val, cat_var) {
$.ajax({
    type: "POST",
    url: "category-get-secondary.php",
    data:'secondary_cat='+val,
    success: function(data){
        $("#secondary_cat").html(data);
        $("#tertiary_cat").html('<option value="">Select specific category</option>')
    }
});
}

I'm not being able to pass both the select and input values onto the next page....

I'm only able to pass the select value and not the input value

9
  • Use $("#primary_cat").val() in the function to get the value of the other input. Commented Apr 8, 2016 at 23:06
  • @Barmar How do I add it in my Ajax please? Commented Apr 8, 2016 at 23:11
  • Use .ajax() method and pass the argument in json format via POST http method, like this question stackoverflow.com/a/15637150/4386714 Commented Apr 8, 2016 at 23:20
  • @Barmar sir what is cat_var in function getSecondaryCat(val, cat_var) {...} Commented Jul 11, 2020 at 16:33
  • @KUMAR No idea. It's not used. Commented Jul 11, 2020 at 17:58

1 Answer 1

1

Try this:

function getSecondaryCat(val, cat_var) {
    var category_typex = $('#category_typex').val();
    $.ajax({
        type: "POST",
        url: "category-get-secondary.php",
        data:{secondary_cat:val, category_typex:category_typex},
        success: function(data){
            $("#secondary_cat").html(data);
            $("#tertiary_cat").html('<option value="">Select specific category</option>');
        }
    });
}
Sign up to request clarification or add additional context in comments.

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.