Search code examples
jsonjspjavabeans

How Do I Create a Disabled Parameter in a JSP File?


How do create a disabled parameter to hold a employee ID and pass that parameter with the form data to a servlet and alter the database?

Any suggestions to get the value of the disabled employeeID are appreciated.

<form class="form-horizontal" id="form_editemp">
        <fieldset>

            <!-- Form Name -->
            <legend>Edit Employee Information</legend>

            <!-- Text input-->
             <div class="form-group">
             <label id="empid" class="col-md-4 control-label" for="empid"    >Employee ID:</label>
             <div class="col-md-4">
                <input id="empid" name="empid" type="text"
                          class="form-control input-sm"
                          value = "${emp.empid}" disabled> <span   class="help-block"> </span>
                </div>
            </div>

            <!-- Text input-->
            <div class="form-group">
                <label class="col-md-4 control-label" for="empName">Employee   Name:</label>
                <div class="col-md-4">
                    <input id="empName" name="empName" type="text"
                          class="form-control input-md"
                        required="" value = "${emp.empName}" > <span   class="help-block"> </span>
                </div>
            </div>

            <!-- Text input-->
            <div class="form-group">
                <label class="col-md-4 control-label" for="hireDate">Hire   Date:</label>
                <div class="col-md-4">
        <input id ="date" name="hireDate" type="text" class="form-control"   value = "${emp.hireDate}"><span class="input-group-addon"><i class="glyphicon   glyphicon-th"></i></span>
    </div>
            </div>  

            <!-- Button (Double) -->
            <div class="form-group">
                <label class="col-md-4 control-label" for="submitempedit">Submit</label>
                <div class="col-md-4">
                    <button id="submitempedit" name="submitempedit"   class="btn btn-primary">Submit</button>
                </div>
            </div>
            </fieldset>
    </form>

 <script>
 $('#date').datepicker({

    });
 </script>

 <script>
$('#submitempedit').click(function() {
//Open modal (popup) window
//Define variable for the form inside the modal
var $form = $("#form_editemp");
//Javascript object based on form calling the function below
var data = getFormData($form);
var empid = document.getElementById("empid").getAttribute("value");
console.log(x);
//Json string by converting javascript object above to json
var json = JSON.stringify(data);

Solution

  • Display it as simple text, and add a hidden field to your form:

    <input type="hidden" name="empid" value="${emp.empid}"/>