Reputation: 31
it is not working for me.. is this correct. i doubt in this line data: "ch=" + dropdown&"ch2=" + dropdown2&"ch3=" + dropdown3,
can any please check this ones for me
<script>
function dynamic_Select(dropdown) {
$.ajax({
type: "GET",
url: 'att-filt.php',
data: "ch=" + dropdown&"ch2=" + dropdown2&"ch3=" + dropdown3,
dataType: "html",
success: function(html){ $("#txtResult").html(html); $("#firstresult").css("display", "none"); }
});
}
</script>
<form>
<input type="text" id="dropdown" name="dropdown">
<input type="text" id="dropdown2" name="dropdown1">
<input type="text" id="dropdown3" name="dropdown2">
<input type="button" value="submit" onclick="dynamic_Select(this.value)">
</form>
Upvotes: 0
Views: 59
Reputation: 177786
The ampersand &
needs to be inside the quotes and you need the actual values too - it is not enough to just mention the dropdown names.
Try this
data: "ch=" + $("#dropdown").val() +
"&ch2=" + $("#dropdown2").val()+
"&ch3=" + $("#dropdown3").val(),
Please note that your IDs also do not match your NAMEs so you may be confused as to what you are getting on the server
To put it in context of your Ajax call, you want
$("input[type=button]").on("click", function() {
$.ajax({
type: "GET",
url: 'att-filt.php',
data: "ch=" + $("#dropdown").val() +
"&ch2=" + $("#dropdown2").val()+
"&ch3=" + $("#dropdown3").val(),
dataType: "html",
success: function (html) {
$("#txtResult").html(html);
$("#firstresult").css("display", "none");
}
});
});
Alternatively use seriealize:
$("input[type=button]").on("click", function() {
$.ajax({
type: "GET",
url: 'att-filt.php',
data:$("form").serialize(),
dataType: "html",
success: function (html) {
$("#txtResult").html(html);
$("#firstresult").css("display", "none");
}
});
});
Upvotes: 2
Reputation: 11371
You're concatenting it wrong. The &
must be within quotes. and you're also missing the concat
operator (+
) at places
Yours : data: "ch=" + dropdown&"ch2=" + dropdown2&"ch3=" + dropdown3
Correct : data: "ch=" + dropdown + "&ch2=" + dropdown2 + "&ch3=" + dropdown3
And dropdown
, dropdown2
, dropdown3
values won't work the way they are. It must be selected from the element, like this :
data: "ch=" + $("#dropdown").val()+"&ch2=" + $("#dropdown2").val()+"&ch3=" + $("#dropdown3").val()
And remove the onclick
to use jQuery's click
:
$("input[type=button]").on("click", function dynamic_Select() {
$.ajax({
type: "GET",
url: 'att-filt.php',
data: "ch=" + dropdown + "&ch2=" + dropdown2 + "&ch3=" + dropdown3,
dataType: "html",
success: function (html) {
$("#txtResult").html(html);
$("#firstresult").css("display", "none");
}
});
});
Upvotes: 1