sql >> Database teknologi >  >> RDS >> Mysql

Indstil inputværdi ved valg af mulighed i php

Dette er PHP-kode:-

<form>
    <select name="customer" id="customer_id">
        <option value="">-- Select customer Name -- </option>
        <option value="1">John</option>
        <option value="2">Smith</option>                               
    </select>
   Address: <input name="add" type="text" value="">
   Mobile:  <input name="mobile" type="text" value="">
    EMail-Id:<input name="email" type="text" value="">
 </form>

Dette er JS-kode:-

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
    $(document).ready(function() {
        $("#customer_id").change(function() {
                var id = $(this).val();
                var dataString = 'cid='+id;
                //alert(dataString);
                $.ajax({
                    url: 'dataAjax.php',
                    type: 'post',
                    data: dataString,
                    success: function(response) {

                      // Parse the jSON that is returned
                        var Vals    =   JSON.stringify(response);
                        // These are the inputs that will populate
                        $("input[name='add']").val(Vals.add);
                        $("input[name='mobile']").val(Vals.mobile);
                        $("input[name='email']").val(Vals.email);
                         }
            });
        });
    });
</script>

Dette er en anden PHP-filkode:-

<?php
// This is where you would do any database call
if(!empty($_POST)) {
    // Send back a jSON array via echo
    echo json_encode(array("add"=>'India',"mobile"=>'1234567890','email'=>'[email protected]'));

}
?>


  1. Importerer MS ACCESS DB til mySql?

  2. docker mysql på anden port

  3. Division i Mysql-forespørgsel

  4. Sådan ændres kolonnestørrelse i MySQL