java - Display dynamic mysql table from radio button input using json -
i have form radio buttons, when clicked pass servlet fetches data mysql table , displays in same page checkbox.
<input type="radio" name="id" value="1"> <input type="radio" name="id" value="2"> <script> $(document).ready(function(){ $('input[name=id]').change(function (){ var var_name = $(this).val(); console.log(var_name); $.getjson("servletcode", "id="+var_name,function(data){ var myvalues = data.tohtml; $("#guts").html(myvalues); }); }); }); </script> my servlet code is:
jsonobject jsonobj = new jsonobject(); list<string> mylist = new arraylist<string>(); username = rs.getstring("name"); id = rs.getstring("userid"); mylist.add(username); mylist.add(userid); jsonobj.put("tohtml", mylist.toarray()); response.setcontenttype("application/json"); response.getwriter().write(jsonobj.tostring()); i want create table using these values "id" , "name" , check box. when check box clicked need display "marks" fetched mysql again.
if understand correctly, json
{"tohtml":["somenamevalue", "someuserid"]} however, if you're going have multiple username-id pairs, need own json object. easier iterate on them
what you'll want use javascript create table
var table = "<table>"; table += "<thead><tr><th>username</th><th>id</th></tr></thead>"; table += "<tbody>"; // loop through array elements , create rows table += "</tr><td>" + /* username json */ + "</td>"; table += "<td>" + /* userid json */ + "</td>"; // add javascript callback checkbox display grades in similar way // done loop table += "</tbody>"; you can append table other html element , make visible.
Comments
Post a Comment