RCR Posted July 27, 2012 Share Posted July 27, 2012 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 More sharing options...
scootstah Posted July 28, 2012 Share Posted July 28, 2012 Change onchange="this.empselect.submit()" to onchange="empselect.submit()" Link to comment https://forums.phpfreaks.com/topic/266317-select-onchange-submit-form/#findComment-1365007 Share on other sites More sharing options...
kicken Posted July 28, 2012 Share Posted July 28, 2012 onchange="this.form.submit()" is a good generic option. All form input elements have a .form property that references it's <form> element. Link to comment https://forums.phpfreaks.com/topic/266317-select-onchange-submit-form/#findComment-1365020 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.