javascript - populate text boxes depend on drop-down selection in php -


i research in google , stack overflow answer there lot of answer cannot able want.

i have 2 drop down menus , 3 text boxes.

php code :

    <select onchange="firstdropdownclick()"> </select> 

script code :

            <script type="text/javascript">            function firstdropdownclick() {  var selectdwn = document.getelementbyid("id_dwn"); var selectedvalue = selectdwn.options[selectbox.selectedindex].value;                   } 

in "firstdropdownclick()" want codes following :

1.select data database according selected value.

2.fill text boxes that.

3.fill second drop down according value of first drop-down menu.

i need example codes. because stuck , dont know how .

thanks in advance.

your html code

    <select name="reg_number" id="reg_number">        <option value="1">reg1</option>        <option value="2">reg2</option>        <option value="3">reg3</option>     </select>     <input type="text" name="first_name" id="first_name"> 

your jquery(make sure include jquery file)

 $(document).ready(function(){    $('#reg_number').change(function(){    var reg_number = $(this).val();    var data_string;     data_string = 'reg_number='+reg_number;     $.post('ajax_file.php',data_string,function(data){           var data= jquery.parsejson(data);            $('#first_name').val(data.first_name)        });    });  }); 

your php code (ajax_file.php)

 <?php        $reg_number =$_post['reg_number'];         //run query here fetch result , store in variable $data      echo json_encode($data);      exit();`   ?> 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -