Reputation:
I have a problem to get the value in the input for onchange function. Below is my coding:
<div class="form-group">
<label>Choose Book:<span style="color:red;"> *</span></label>
<select class="form-control" id="publisher" name="publisher" title="publisher">
<option value="">Please Select</option>
<?php
$sql_branch = 'select * from book_lending where status=1 order by id';
$arr_branch = db_conn_select($sql_branch);
foreach ($arr_branch as $rs_branch) {
echo '<option value="' . $rs_branch['id'] . '">' . $rs_branch['title'] . '</option>';
}
?>
</select>
</div>
<div class="form-group">
<label for="cp1" class="control-label">Book Stock<span style="color:red;"> *</span></label>
<input readonly="readonly" type="text" class="form-control" id="editor" name="editor" title="editor" value="" >
</div>
<script>
$(function(){
$("#publisher").change(function(){
var displayid=$("#publisher option:selected").text();
$("editor").val(displayid);
})
})
</script>
Below is output picture:
I need to show the input value if I onchange in the id is publisher, then id editor will show the value.Hope someone can guide me which part I get the wrong. Thanks.
Upvotes: 0
Views: 45
Reputation: 768
Try this:-
<script>
$(function(){
$("#publisher").change(function(){
var value=$("#publisher").val();
$("#editor").val(value);
})
})
</script>
Upvotes: 0
Reputation: 2211
you are missing editor id
$(function(){
$("#publisher").change(function(){
var displayid=$(this).val();
$("#editor").val(displayid);
})
})
Upvotes: 1