0

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.

2
  • did you check var_dump($_POST); ? Commented Mar 28, 2014 at 18:38
  • @gonzalon : Yes, I did, it gives me array(0) Commented Mar 28, 2014 at 21:03

1 Answer 1

1

Change myval to data.

Moreeee charactersss....

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Kolby, I changed mayval to data in my php, but I got same error and I don't understand what you mean by more characters

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.