Top Ad unit 728 × 90

setting values in dropdownlist from database using jquery and php

I hope, you already have a little bit knowledge of basic HTML, Java Script and php. So, you need to create 2 or 3 files to set the values  in dropdownlist from database using jquery and php. This is really very simple step to do. First create a file with connection information called my_con.php after creating database and table in mysql.

Then create a sample.html file and within a form write down the following code.

 1) Html File: sample.html
<div class="asen-form-row">
       <label class="asen-form-label">Department <span class="required">*</span></label>
            <div class="asen-form-item">
                  <select class="required medium" id="cmbMstFileDept">

 Then create a java script file with the below code and save it as file.js and link it into main html file.

2) Jquery File:
$("#cmbMstFileDept").load("asen_getMstDeptNmIntoMstFile.php", function(data) {      $("#cmbMstFileDept").val(data); 
Then create a php file with the below code and call it into .js file
3) Processing file: asen_getMstDeptNmIntoMstFile.php

    require_once ("my_con.php");

    $searchedMstFileCd = $_POST['id'];
    $asenmod = $_POST['asenmod'];
    $get_deptid_sqltxt = "SELECT Dept_Nm FROM mst_dept order by Dept_Nm asc";

    $get_res = mysql_query($get_deptid_sqltxt);
    $get_deptnm1 .= "<option value='' selected>Select Department</option>";
    while($row = mysql_fetch_array($get_res)) {
        $get_deptnm = $row['Dept_Nm'];
        $get_deptnm1 .= "<option value='$get_deptnm'>$get_deptnm</option>";

    echo $get_deptnm1;

Finally try to run the main sample.html  file and you will see the proper result. I have created this script and already have tested and worked successfully.

If you want to know anything else please let me know with your comments.
setting values in dropdownlist from database using jquery and php Reviewed by Ashok Sen on 17:04:00 Rating: 5

No comments:

Thanks for sharing your valuable comments.

All Rights Reserved by ASENwebmedia © 2014 - 2015
Powered By Blogger, Developed by Asenwebmedia

Contact Form


Email *

Message *

Powered by Blogger.