Matarishvan
Matarishvan

Reputation: 2422

cannot receive POST values in php submitted through select onChange

Well i'm submitting form through onChange of select

<form name="selForm" id="selForm" type="POST>
       <select name="sel_status" id="sel_status">
          <option value="one">one</option>
          <option value="two">two</option>
       </select>
</form>

My jQuery Code

$('#sel_status').change(function(){
    $('#selForm').submit();
});

And then i'm echoinging the value submitted in php

echo $_POST['sel_status'];

My network tab in Chrome showing 302 status

enter image description here

So how to submit the form through onChange of select and receive those values in php?

Upvotes: 2

Views: 427

Answers (4)

LugiHaue
LugiHaue

Reputation: 2802

Add form action="yourphpfile.php" and change method="POST".

Try:

echo $_POST['sel_status'];

Upvotes: 0

Hearner
Hearner

Reputation: 2729

<form name="selForm" id="selForm" type="POST">

The action is missing and it's method, not type

Upvotes: 1

TheBalco
TheBalco

Reputation: 405

You've got an error in your HTML code.

First, there is a " missing (after POST) and this attribute is called method, not type. So the correct code should be:

<form name="selForm" id="selForm" method="post">
    <select name="sel_status" id="sel_status">
        <option value="one">one</option>
        <option value="two">two</option>
    </select>
</form>

If your PHP code is in an other file, you also have to set the action="yourfile.php" attribute

Upvotes: 1

Mangesh Sathe
Mangesh Sathe

Reputation: 2177

Use $_POST['sel_status'];

You cannot use echo $_POST['selForm']; "selForm" is name of the form.

Upvotes: 0

Related Questions