Jump to content

Select - onchange submit form


RCR

Recommended Posts

Hello,

 

I need some help with this functionality.

 

I have a table with data:

EMPNO ENAME GRADE

-------- ------- ---------

100 JACK A

101 JOHN B

103 TOM A

 

I need to create a select item that will list all the names. I want to be able to select one of the names from the drop down. I am passing the grade as a hidden element of the form. I don't want to follow the selection from the drop down with  a submit button. Although the list is displaying the names, I really need the grade for further processing, although the name is also important.  So, i figured  the onchange : this.formname.submit(), might help. However I can't seem to understand where I am making a mistake. This is the code I've written. Do I need some additional javascript code somewhere. If so what do I write ?

 

<form name="empselect" action="?emp_select" method="post">

<h3>Select the Employees Name:

<select name="employee" id="employee" class="styled-select" onchange="this.empselect.submit()">

<option value="">Select an employee </option>

<?php foreach ($employees as $employee):?>

<option value="<?php echo($employee['empno']);?>">

<?php echo($employee['ename'].'-'.$employee['grade']);?></option>

<?php endforeach;?>

</select> </h3> <br>

<input type="hidden" name="grade" value="<?php echo $employee['grade']?>">

</form>

 

In the php part that was written above the form, I wrote:

if (isset($_GET['emp_select']))

{

$grade=$_POST['grade'];

echo "grade is" . $grade;

}

 

However, it is not doing the echo part. Am I making a mistake somewhere. I need to get the grade for further processing on the form, and I needed it from the select.

 

Your kind assistance is greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/266317-select-onchange-submit-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.