• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple variable data getting problem when select radio button

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Friends,

I have pasted below my code, I need to get two values & it pass to the VisitDetails Servlet. One is "visit_id" by radio button and second is "visit_type" but as per the below code I am getting only first row value of "visit_type" which fetched from the database. But when user will select any other row I needs that row's "visit_type" value only.

Please any one help out me.

<center>
<form method="post" action="VisitDetails">
<table border="1">
<tr>
<td>Visit Type</td>
<td>Visit Code</td>
<td>Visit Date</td>
<td>Visit Status</td>
<td>Category</td>
<td>Select Visit</td>
</tr>
<%
try {
String patMRD = request.getParameter("pMRD_no");
String dburl = "jdbc:mysql://localhost:3306/db";

Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(dburl, "usr", "password");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT v.visit_type AS 'visit_type', v.visit_code AS 'visit_code', "
+ "v.visit_date_time AS 'visit_date_admission_date',"
+ " IF(v.visit_closed_yesno=1,'Closed','Open') AS 'visit_status',"
+ " pcm.description AS 'visit_patient_category', v.id FROM visit v, "
+ "patient_category_master pcm WHERE DATE_FORMAT(v.visit_date_time,'%Y-%m-%d')"
+ " BETWEEN SUBDATE(NOW(),'201') AND NOW() AND v.patient_id='" + patMRD + "'AND v.patient_category_id=pcm.id;");

while (rs.next()) {

String visit_type = rs.getString("visit_type");
String visit_code = rs.getString("visit_code");
String visit_date_admission_date = rs.getString("visit_date_admission_date");
String visit_status = rs.getString("visit_status");
String visit_patient_category = rs.getString("visit_patient_category");
String visit_id = rs.getString("id");
%>
<tr>
<td><%= visit_type%></td>
<td><%= visit_code %></td>
<td><%= visit_date_admission_date %></td>
<td><%= visit_status %></td>
<td><%= visit_patient_category %></td>
<td><%= visit_id %></td>
<td><input type="radio" name="visitID" value="<%= visit_id%>" />
<!-- <input type="submit" name="visitType" value="<%= visit_type%>"/> -->
<input type="hidden" name="visitType" value="<%= visit_type%>" />
</tr>

<%
}
} catch (SQLException e) {
e.printStackTrace();
}
%>
</table>
<table>
<tr>
<td ><input type="submit" value="Check Visit Details"/></td>
</tr>
</table>
</form>
 
Ranch Hand
Posts: 136
Netbeans IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to new member Hiren,

Your question is not clear make sure the forum members can understand what you exactly trying to say. Also dont put your code like this use the code tag option in forum and paste your code in it so users can understand easily.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, while iterating you are getting <input type="radio" name="visitID" value="<%= visit_id%>" />
now in the same time dynamically generate hidden field as <input type="hidden" name="<%= visit_id%>" value="<%= visit_type%>" />
[HOPE visit_id is unique*]
i.e, now visit_type and visit_id is linked. now now you are getting visit_id on servlet right? now get the associated visit_type as String visitType = request.getParameter("visit_id");

another approach. use separator <input type="radio" name="visitID" value="<%= visit_id%>|<%= visit_type%>" />

second approach could be error prone...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch Hiren Mistry :)

and scriptlet in jsp makes hard to read and maintain your jsp code!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Seetharaman Venkatasamy wrote:and scriptlet in jsp makes hard to read and maintain your jsp code!


Please read this JspFaq entry.
 
reply
    Bookmark Topic Watch Topic
  • New Topic