I have a drop down list:
<select class="form-control" name = "Terminal_ID" id = "Terminal_ID" onchange="updateValue();">
<option>Select</option>
<?php
$query="SELECT * FROM mytable";
$result=mysqli_query($con,$query);
while($rows=mysqli_fetch_array($result2))
{
$tid=$rows['Idcolumn'];
$tn=$rows['Namecolumn'];
?>
<option value="<?=$tn;?>"><?=$tid;?></option>
<?php
}
?>
</select>
and a text input box
<input class="form-control" type="text" id="textboxid" name="tname" />
I have this on updateValue function in javascript:
function updateValue()
{
$('#textboxid').val($('#Terminal_ID').val());
}
$(document).ready(function () {
updateValue();
});
It work's, since it shows the value of $tn
in my text input box. The problem is that, the function change the value of the selection in the dropdown list. and if, i want to use the selection of the drop down to insert some data in my database it sends me the $tn
value, and i need the $tid
value. If I change this <option value="<?=$tn;?>">
to <option value="<?=$tid;?>">
it change the value of the text input box. Is there anything i can modify to this code to get the $tn
as value in text input box and the $tid
as value of the selection?