Composite key option without js.
<form method="POST" name="apple" id="apple" action="tabl.php" target="_blank"> <select class="selectpicker" name="user" id="user" data="<?=$matn?>" > <option disabled selected >Выбрать сотрудника</option> <? foreach($row as $k=>$val){ $matn=$val['mname']; $matn=substr($matn,0,-6); ?> <option value="<?=echo $val['myid'] . "/". $matn ?>" id="link" > <?=$val['mname']?> </option> <? } ?> </select> </form>
On the server we do:
$user = explode("/", $_POST['user']);
The first element is id, the second is name
Option with js:
<form method="POST" name="apple" id="apple" action="tabl.php" target="_blank"> <input type="hidden" name="user_name" value="1"> <select class="selectpicker" name="user" id="user" data="<?=$matn?>" > <option disabled selected >Выбрать сотрудника</option> <? foreach($row as $k=>$val){ ?> <option value="<?=$val['myid']?>" id="link" > <?=$val['mname']?> </option> <? } ?> </select> </form>
function setName(elem) { var text = elem.options[elem.selectedIndex].text; text = text.substr(0, text.length - 6); document.getElementById('user_name').value = text; }
<input id="user_name" name="user_name" type="hidden" /> <select name="user" onchange="setName(this)"> <option value="1">Алексей123456</option> <option value="2">Василий123456</option> </select>
Well, on the back already get from the post $_POST['user_name'] $_POST['user']