I've created a form with 3 select tag in my HTML, tried to create an array from it by jquery and send it to PHP. I want to load some data from my php and show in my html file. Here is my code
HTML code
<form name="myform">
<select name="select1">
<option value="">select1</option>
<option value="11">value11</option>
<option value="12">value12</option>
</select>
<select name="select2">
<option value="">select2</option>
<option value="21">value21</option>
<option value="22">value22</option>
</select>
<select name="select3">
<option value="">select3</option>
<option value="31">value31</option>
<option value="32">value32</option>
</select>
</form>
<div id="mydiv"></div>
ajax code
$("form select").bind("change", function () {
var myval = jQuery.param($('form select').serializeArray());
alert(myval);
$.ajax({
type: "POST",
url: "test.php",
data: myval
});
});
$("#mydiv").load("myfile.php");
In alert(myval) it alerts the value like this
select1=&select2=&select3=
this message changes every time I change on of my select tags. so I think this part of code has no problem!
PHP code
$postarr = $_POST['myval'];
var_dump($postarr)//gives me NULL
var_dump($_POST)//gives me array(0);
echo $postarr[0];
this message shows in my HTML(in #mydiv)
Notice: Undefined index: myval ...
my question is what is my problem and what index I must use in my php code.
var_dump($_POST);?