get value in textbox from database according to seleceted dropdown item in php -
so i've change text box data according option selected in dropdown. want text box data fetched database.
for eg: if choose airmail current frank value of airmail should displayed in text box database.
here code
<div> <form action="alertfrank.php" method="post" class="boxin" id="dropdown"> <select name="type_post" required id="type_post" > <option value="select post type" selected>select post type</option> <option value="airmail" >airmail</option> <option value="airmail ad">airmail ad</option> <option value="airmail speed post">airmail speed post</option> <option value="speed post">speed post</option> <option value="book post">book post</option> <option value="ordinary post">ordinary post</option> <option value="registered post">registered post</option> <option value="registered ad">registered ad</option> <option value="registered parcel">registered parcel</option> <option value="parcel">parcel</option> <option value="courier">courier</option> </select> <br/> <br/> current frank value <?php echo '<input type="number" name="value_frank" value="">'; ?> <br/> <br/> new frank value <input type="number" name="new_frank" placeholder="new frank value"/> <br/> <br/> <input type="submit" name="submit" value="change value" id="sub"/> <br/> <br/> <br/> <br/> </form> </div> <?php if (null !== (filter_input(input_post, 'submit'))) { mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("disp") or die(mysql_error()); $type_post = (filter_input(input_post, 'type_post')); $_session['type_post'] = $type_post; $q = mysql_query("select value_frank frank type_post='" . $_session['type_post'] . "'") or die(mysql_error()); $value_frank = mysql_fetch_row($q); $_session['value_frank'] = $value_frank; } ?>
i want current frank value displayed in value_frank feild..and before submit.
add onchange()
select this,
<select name="type_post" required id="type_post" onchange="get_data(this.value)" > <option value="select post type" selected>select post type</option> <option value="airmail" >airmail</option> <option value="airmail ad">airmail ad</option> <option value="airmail speed post">airmail speed post</option> <option value="speed post">speed post</option> <option value="book post">book post</option> <option value="ordinary post">ordinary post</option> <option value="registered post">registered post</option> <option value="registered ad">registered ad</option> <option value="registered parcel">registered parcel</option> <option value="parcel">parcel</option> <option value="courier">courier</option> </select>
then in script write ajax function fetch data server.
this script.
function get_data(value){ $.ajax({ url: "nameof ajax file .php", type: "post", datatype: "html", async: false, data: {value: value} success: function(data) { //here can populate required fields based on value database } }); }
in ajax file value db based on value selected.and display in text boxes.
you have move database part file,
mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("disp") or die(mysql_error()); $type_post = (filter_input(input_post, 'type_post')); $q = mysql_query("select value_frank frank type_post='" . $type_post . "'") or die(mysql_error()); $value_frank = mysql_fetch_row($q); $val_fra = $value_frank; echo $val_fra;// here no need use sessions @ all.
Comments
Post a Comment