0

I want to get the ID value in the department_tbl and put it in the TextBox instead of Alert.

<select name="departmentlvl" id="departmentlvl">
    <option value="" >Choose Department Level</option>
    <?php
        $qry="Select * from department_tbl";
        $result=mysqli_query($conn,$qry);
        while($row = mysqli_fetch_array($result))
        {
            extract($row);
            echo "<option value='".$department_id."'>".$departmentDesc."
         </option>";

        }
    ?> 
</select>
<input type="text" id="" value="">// put the id value here($department_id)

//jquery
$(document).ready(function() {
    $("#departmentlvl").on('change', function () {
        alert($(this).val());
    });
});

2 Answers 2

2

Make a id attribute for the input field i.e

 <input type="text" id="department_id" value="">

On the jquery function just put the value

//jquery
$(document).ready(function() {
$("#departmentlvl").on('change', function () {
    $("#department_id").val($(this).val());
  });});
Sign up to request clarification or add additional context in comments.

1 Comment

glad... i helped :)
0

you can give id or name to text field and later access it using the same e.g

<input type="text" name="myfirstinput" id="firstinput" />

//using name
$("input[name=myfirstinput]").val("demo");

//using id 
$("#firstinput").val("demo");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.