www.webdeveloper.com
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Select - onchange submit form

    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.

  2. #2
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,078
    I am not sure, it is possible to use a querystring, or a GET URI, with a POST !

  3. #3
    Join Date
    Feb 2012
    Location
    Bokaro Steel City (Jharkhand), India!
    Posts
    192
    Use
    HTML Code:
    onchange="submit()"
    instead of
    HTML Code:
    onchange="this.empselect.submit()"
    Last edited by TheAliveWinner; 07-27-2012 at 09:06 PM. Reason: I am back after 2 months! :) It hurts!
    "It will never rain roses: when we want to have more roses, we must plant more roses."
    - George Eliot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



Recent Articles