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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.