Skip to main content
dando formato al codigo
Origen Enlace
<html>
   <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
   <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
    $(function(){
    $(document).on('change','#mySelect',function(){ 
        var value = $(this).val();
      $('#myInput').val(value);
      $('#myInput2').val(value);
    });
  });
</script>
<?php
require ('conexion.php');
if (!$conn->set_charset("utf8")) {
        printf("Error loading character set utf8: %s\n", $conn->error);
    }
$result = $conn->query("SELECT * from business");
 
    
    //config form
    echo '<form accept-charset="utf-8" action="generarqr.php" method="post">';
     echo '<select id="mySelect">';
     echo '<option value="" disabled selected>Seleccione la empresa</option>';
 while ($row = mysqli_fetch_array($result)) {
echo '<option value="'. $row['Nombre'].'">'. $row['Nombre'].'</option>';
 }
echo '</select>';
echo '<input id="myInput"  name="data"/>';

echo '<select id="mySelect2">';
     echo '<option value="" disabled selected>Seleccione la empresa</option>';
 while ($row = mysqli_fetch_array($result)) {
echo '<option value="'. $row['id'].'">'. $row['Nombre'].'</option>';
 }
echo '</select>';
echo '<input id="myInput2"  name="ids"/>';
echo '<input type="submit" value="GENERATE"></form>';

?>

      <script>
        $(function () {
            $(document).on('change', '#mySelect', function () {
                var value = $(this).val();
                $('#myInput').val(value);
                $('#myInput2').val(value);
            });
        });
      </script>
   </head>
</html>

<?php
    require('conexion.php');
    if (!$conn->set_charset("utf8")) {
        printf("Error loading character set utf8: %s\n", $conn->error);
    }

    $result = $conn->query("SELECT * from business");

    //config form
    echo '<form accept-charset="utf-8" action="generarqr.php" method="post">';
    echo '<select id="mySelect">';
    echo '<option value="" disabled selected>Seleccione la empresa</option>';
    while ($row = mysqli_fetch_array($result)) {
        echo '<option value="' . $row['Nombre'] . '">' . $row['Nombre'] . '</option>';
    }
    echo '</select>';
    echo '<input id="myInput"  name="data"/>';

    echo '<select id="mySelect2">';
    echo '<option value="" disabled selected>Seleccione la empresa</option>';
    while ($row = mysqli_fetch_array($result)) {
        echo '<option value="' . $row['id'] . '">' . $row['Nombre'] . '</option>';
    }
    echo '</select>';
    echo '<input id="myInput2"  name="ids"/>';
    echo '<input type="submit" value="GENERATE"></form>';

?>
set_charset("utf8")){printf("Error loading character set utf8: %s\n", $conn->error);}$result = $conn->query("SELECT * from business");//config formecho '';echo '';echo 'Seleccione la empresa';while($row = mysqli_fetch_array($result)){echo ''. $row['Nombre'].'';}echo '';echo '';

echo ''; echo 'Seleccione la empresa'; while ($row = mysqli_fetch_array($result)) { echo ''. $row['Nombre'].''; } echo ''; echo ''; echo '';

?>

<html>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
    $(function(){
    $(document).on('change','#mySelect',function(){ 
        var value = $(this).val();
      $('#myInput').val(value);
      $('#myInput2').val(value);
    });
  });
</script>
<?php
require ('conexion.php');
if (!$conn->set_charset("utf8")) {
        printf("Error loading character set utf8: %s\n", $conn->error);
    }
$result = $conn->query("SELECT * from business");
 
    
    //config form
    echo '<form accept-charset="utf-8" action="generarqr.php" method="post">';
     echo '<select id="mySelect">';
     echo '<option value="" disabled selected>Seleccione la empresa</option>';
 while ($row = mysqli_fetch_array($result)) {
echo '<option value="'. $row['Nombre'].'">'. $row['Nombre'].'</option>';
 }
echo '</select>';
echo '<input id="myInput"  name="data"/>';

echo '<select id="mySelect2">';
     echo '<option value="" disabled selected>Seleccione la empresa</option>';
 while ($row = mysqli_fetch_array($result)) {
echo '<option value="'. $row['id'].'">'. $row['Nombre'].'</option>';
 }
echo '</select>';
echo '<input id="myInput2"  name="ids"/>';
echo '<input type="submit" value="GENERATE"></form>';

?>

</head>
set_charset("utf8")){printf("Error loading character set utf8: %s\n", $conn->error);}$result = $conn->query("SELECT * from business");//config formecho '';echo '';echo 'Seleccione la empresa';while($row = mysqli_fetch_array($result)){echo ''. $row['Nombre'].'';}echo '';echo '';

echo ''; echo 'Seleccione la empresa'; while ($row = mysqli_fetch_array($result)) { echo ''. $row['Nombre'].''; } echo ''; echo ''; echo '';

?>

<html>
   <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
   <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script>
        $(function () {
            $(document).on('change', '#mySelect', function () {
                var value = $(this).val();
                $('#myInput').val(value);
                $('#myInput2').val(value);
            });
        });
      </script>
   </head>
</html>

<?php
    require('conexion.php');
    if (!$conn->set_charset("utf8")) {
        printf("Error loading character set utf8: %s\n", $conn->error);
    }

    $result = $conn->query("SELECT * from business");

    //config form
    echo '<form accept-charset="utf-8" action="generarqr.php" method="post">';
    echo '<select id="mySelect">';
    echo '<option value="" disabled selected>Seleccione la empresa</option>';
    while ($row = mysqli_fetch_array($result)) {
        echo '<option value="' . $row['Nombre'] . '">' . $row['Nombre'] . '</option>';
    }
    echo '</select>';
    echo '<input id="myInput"  name="data"/>';

    echo '<select id="mySelect2">';
    echo '<option value="" disabled selected>Seleccione la empresa</option>';
    while ($row = mysqli_fetch_array($result)) {
        echo '<option value="' . $row['id'] . '">' . $row['Nombre'] . '</option>';
    }
    echo '</select>';
    echo '<input id="myInput2"  name="ids"/>';
    echo '<input type="submit" value="GENERATE"></form>';

?>
Origen Enlace

Enviar valores de un select mysql a varios inputs en php

Tengo un selectbox poblado desde mysql desde una tabla con dos campos (id y nombre). El selectbox muestra la lista de nombres. Necesito que al seleccionar un elemento del select envíe el id a un input text y el nombre a otro input text. Por ahora, he logrado pasar con javascript el valor nombre a un imput text, pero no logro pasar el id al otro input text.

Éste es el código que tengo.

<html>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script>
    $(function(){
    $(document).on('change','#mySelect',function(){ 
        var value = $(this).val();
      $('#myInput').val(value);
      $('#myInput2').val(value);
    });
  });
</script>
<?php
require ('conexion.php');
if (!$conn->set_charset("utf8")) {
        printf("Error loading character set utf8: %s\n", $conn->error);
    }
$result = $conn->query("SELECT * from business");
 
    
    //config form
    echo '<form accept-charset="utf-8" action="generarqr.php" method="post">';
     echo '<select id="mySelect">';
     echo '<option value="" disabled selected>Seleccione la empresa</option>';
 while ($row = mysqli_fetch_array($result)) {
echo '<option value="'. $row['Nombre'].'">'. $row['Nombre'].'</option>';
 }
echo '</select>';
echo '<input id="myInput"  name="data"/>';

echo '<select id="mySelect2">';
     echo '<option value="" disabled selected>Seleccione la empresa</option>';
 while ($row = mysqli_fetch_array($result)) {
echo '<option value="'. $row['id'].'">'. $row['Nombre'].'</option>';
 }
echo '</select>';
echo '<input id="myInput2"  name="ids"/>';
echo '<input type="submit" value="GENERATE"></form>';

?>

</head>
set_charset("utf8")) { printf("Error loading character set utf8: %s\n", $conn->error); } $result = $conn->query("SELECT * from business"); //config form echo ''; echo ''; echo 'Seleccione la empresa'; while ($row = mysqli_fetch_array($result)) { echo ''. $row['Nombre'].''; } echo ''; echo '';

echo ''; echo 'Seleccione la empresa'; while ($row = mysqli_fetch_array($result)) { echo ''. $row['Nombre'].''; } echo ''; echo ''; echo '';

?>