aspose file tools*
The moose likes JSP and the fly likes Multiple variable data getting problem when select radio button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Multiple variable data getting problem when select radio button" Watch "Multiple variable data getting problem when select radio button" New topic
Author

Multiple variable data getting problem when select radio button

Hiren Mistry
Greenhorn

Joined: Jul 14, 2011
Posts: 1

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>
Sabarish Venkat
Ranch Hand

Joined: Jan 18, 2012
Posts: 136

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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 28, 2008
Posts: 5575

Welcome to JavaRanch Hiren Mistry :)

and scriptlet in jsp makes hard to read and maintain your jsp code!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61772
    
  67

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

Please read this JspFaq entry.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple variable data getting problem when select radio button