I have a problem when populate combobox with data from query. And when I change the combobox, I want to set value in the textbox or hidden with selected onchange combobox.
When the first combobox that work but when I change the second combobox, not set value to textbox or hidden value.
<script type='text/javascript'>
$(function() {
$('#myselect').change(function() {
var x = $(this).val();
$('#myhidden').val(x);
});
});
</script>
<input type='text' id='myhidden' value=''>
<?php
$result2 = mysql_query("select id_users, fullname from users where status='1'");
echo'<select name="iduserowner" class=form-control id=myselect>';
while($data2 = mysql_fetch_array($result2)) {
echo '<option value="'.$data2['id_users'].'">'.$data2['fullname'].'</option>';
}
echo '</select>';
?>
as I understand you want to put your selected value into your hidden input. try this:
<?php $sql = "SELECT id_users, fullname
FROM users
WHERE status = '1'";
$res = mysql_query( $sql );
?>
<input type="text" id="myhidden" value="">
<select onChange="hideSelected();" name="iduserowner" class="form-control" id="myselect" >
<? while( $result = mysql_fetch_array( $res, MYSQL_ASSOC )){ ?>
<option value="<?= $result[ 'id_users' ]; ?>"><?= $result[ 'fullname' ]; ?></option>
<? } ?>
</select>
<script>
function hideSelected(){
$("#myhidden").val( $("#myselect option:selected").val() );
}
</script>