jquery - display value from database into HTML input tag -
i have drop down list (html select tag) , html form under it. below -
select->
<select name="select-native-1" id="select-native-1" onchange="dbtoform(this)"> <option value="1">employee 1</option> <option value="2">employee 2</option> <option value="3">employee 3</option> <option value="4">employee 4</option> </select>
form ->
<form> <label for="e_name">name</label> <input name="e_name" id="e_name" value="" type="text" data-theme="a"> <label for="date">date</label> <input name="date" id="date" value="" type="date" data-theme="a"> <label for="gender">gender</label> <select name="gender" id="gender" data-role="slider" data-theme="a" data-inline="true"> <option value="male">male</option> <option value="female">female</option> </select> <label for="address">address</label> <textarea name="address" id="address" value="" type="text" data-theme="a"></textarea> <br> <br> <label for="image">add image</label> <input name="image" id="image" value="" type="file" data-theme="a"> <br> <br> <label for="multimedia">add multimedia</label> <input name="multimedia" id="multimedia" value="" type="file" data-theme="a"> <br> <br> <input value="submit" data-role="button" type="submit">
when select value select tag, expected functionality is, based on selected item's id, values database retrieved. doing retrieval of php embedded in js function.
javascript -->
function dbtoform(id) { var id_val = id.value; var name = ''; var url = "http://localhost:81/pg_crud_experiment1/retrieve.php?id="+id_val; $.getjson(url, function(json) { $.each(json, function(i,v) { name += v.name; alert (name); }); $("#e_name").html(name); }); };
here, able values db js function , store in variable. variable has pushed html form field. #e_name
<input>
tag , unable display retrived value in field. there <textarea>
, value prints there without problem.
is limitation <input>
tag? if yes, can used alternate tag?
please note: values retrieved form edit , update purposes. i.e. values populated in form can edited , updated database.
input tags don't have html, have values.
$("#e_name").val(name);
.html()
filling in elements between <tag>
, </tag>
. inputs don't have matching tags that, html go?
Comments
Post a Comment