Solved

How to disolay selected value in JSP dynamically

Posted on 2008-10-18
7
427 Views
Last Modified: 2012-05-05
Hi,
I have two display grid in my JSP page- WorkForcememberIDSearch and WorkForcememberIDSearchHistory.

When ever user select the data using radio button in WorkForcememberIDSearch, based on that I have query database and display values based on the result from DB. Please provide me a sample how can I do this? I am enclosing html page html code please let me know if jsp page is needed.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Workforce Member Screen</title>
<link href="../css/TM_Styles.css" type="text/css" rel="stylesheet" />
<link href="../css/TM_Styles_2.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
	var formInUse = false;
	function setFocus()
		{
 			if(!formInUse) {
  								document.add.lname.focus();
 							}
		}
</script></head>
 
<body onload="setFocus()">
<form action="XXXXXX" method="post" name="add" target="_self">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" class="outertblborder">
    <tr class="tableheading" >
    <td height="25" nowrap="nowrap" colspan="5">
    	<strong> &nbsp;<span class="outtblheading">LTC TrainingRecords Manager</span></strong> 
        <strong> - Workforce Members Screen</strong>    
    	<span class="outtblheading">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        &nbsp;&nbsp;
        User -   	    </span>
    	<input name="username" type="hidden" value="" />
    </td>
  </tr>
  <tr>
  <td width="8" >&nbsp;</td>
    <td width="544" height="369" align="center">
        <table width="97%" border="0" cellpadding="0" cellspacing="0" class="innertableborder tableborder">
          <tr>
            <td height="28" colspan="3" class="tableheading"><p><strong>Workforce  Member ID Search</strong></p></td>
          </tr>
          <tr>
            <td height="28" width="54%" nowrap="nowrap" align="left">&nbsp;<span class="loginfont">
            <strong>Last Name </strong></span>
            <span class="error">(type part or all of a last name)</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
            <td width="46%" nowrap="nowrap">
            <span class="loginfont"><strong>Workforce ID</strong></span>
            <span class="error"> (type in part or all of an ID)</span>        </td>
          </tr>
          <tr>
            <td height="28" align="left">&nbsp;&nbsp;<input type="text" name="lname" id="lname" tabindex="1" maxlength="25"/></td>
            <td><input type="text" name="workfid" id="workfid" tabindex="3" maxlength="10" /></td>
          </tr>
          <tr>
            <td height="28" width="54%" nowrap="nowrap" align="left">&nbsp;<span class="loginfont">
            <strong>First Name </strong></span>
            <span class="error">(type part or all of a first name)</span>        </td>
            <td width="46%">&nbsp;</td>
          </tr>
          <tr>
            <td  height="28" align="left">&nbsp;&nbsp;<input type="text" name="fname" id="fname" tabindex="2" maxlength="25" /></td>
            <td align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<input type="submit" name="Find" id="Find" value=" Find " tabindex="4" /></td>
          </tr>
          <tr>
            <td height="28" >&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td height="27" colspan="2">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="innertableborder loginfont">
                  <tr>
                    <td width="6%"  height="28">&nbsp;</td>
                    <td width="18%"><strong>Full Name</strong></td>
                    <td width="24%"><strong>  Workforce ID  </strong></td>
                    <td width="18%"><strong>Service</strong></td>
                    <td width="34%"><strong>Role </strong></td>
                </tr>
              </table>
            </td>
          </tr>
          <tr>
            <td height="116" colspan="2">
	      <div class="searchlist">
          <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF">
                  <tr>
                    <td width="6%" align="center"><input type="radio" name="radio" id="radio" value="radio" /></td>
                    <td width="18%">&nbsp;</td>
                    <td width="24%">&nbsp;</td>
                    <td width="18%">&nbsp;</td>
                    <td width="34%">&nbsp;</td>
                </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
              </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                    <td>&nbsp;</td>
                  </tr>
                </table>            
      </div>
      </td>
    </tr>
        </table>    
     </td>
    <td width="5">&nbsp;</td>
    <td width="649" height="369" >
<table width="100%"  border="0" cellpadding="0" cellspacing="0" class="innertableborder tableborder">
                       <tr>
            <td height="28" colspan="4" class="tableheading"><p><strong>Workforce Employment  Information Form</strong></p></td>
          </tr>
             <tr>
                <td height="28" width="18%" nowrap="nowrap" class="loginfont">
                &nbsp;<span class="error">* </span><strong>Last Name</strong>&nbsp;&nbsp;                </td>
            <td width="30%">
            <input type="text" name="lname2" id="lname2" tabindex="5" maxlength="25"/>&nbsp;&nbsp;               </td>
               <td width="17%" nowrap="nowrap" class="loginfont"><span class="error">* </span><strong>WorkforceID</strong>&nbsp;
&nbsp;                </td>
               <td width="35%"><input type="text" name="wkid2" id="wkid2" tabindex="13" maxlength="10"/>
&nbsp;&nbsp;               </td>
          	  </tr>
              <tr>
                <td  height="28" nowrap="nowrap" class="loginfont">
                &nbsp;<span class="error">*</span><strong> First Name</strong>&nbsp;&nbsp;                </td>
                <td><input type="text" name="fname2" id="fname2" tabindex="6" maxlength="25"/>
&nbsp;&nbsp;                </td>
                <td nowrap="nowrap" class="loginfont"><span class="error">* </span><strong>Service</strong>&nbsp;&nbsp;</td>
                <td><select name="tenure2" tabindex="14" >
                  <option> XXXX </option>
                </select>&nbsp;&nbsp;                </td>
              </tr>
              <tr>
                <td  height="28" nowrap="nowrap" class="loginfont">
                &nbsp;&nbsp;&nbsp;&nbsp;Middle Initial&nbsp;&nbsp;                </td>
              <td>
                   <input type="mname" name="mname" id="wkfid" maxlength="1" size="5" tabindex="7"/>
&nbsp;&nbsp;                </td>
                <td class="loginfont"><strong>&nbsp;&nbsp;Role </strong></td>
                <td><input type="text" name="role" id="role" tabindex="15" maxlength="10"/></td>
              </tr>
              <tr>
                <td  height="32" nowrap="nowrap" class="loginfont">&nbsp;<span class="error">* </span><strong>Tenure</strong>&nbsp;&nbsp;</td>
              <td>
                    <select name="tenure" tabindex="8" >
                    <option>
                     XXXX                    </option>
                    </select>
&nbsp;&nbsp;                </td>
                <td class="loginfont"><strong>&nbsp;&nbsp;Approver?</strong></td>
                <td><input type="mname" name="approver" id="approver" maxlength="1" size="5" tabindex="16"/></td>
              </tr>
              <tr>
                <td  height="28"><span class="loginfont">&nbsp;<span class="error">* </span><strong>Department</strong></span>                </td>
                <td><select name="dept" tabindex="9" >
                  <option> DL-00000001 </option>
                </select>                </td>
                <td class="loginfont"><strong>&nbsp;&nbsp;Trainer? </strong>                </td>
                <td><input type="mname" name="trainer" id="trainer" tabindex="17" maxlength="1" size="5"/>                </td>
              </tr>
              <tr>
                <td  height="28"><span class="loginfont">&nbsp;<span class="error">*</span><strong> Job Title</strong></span>                </td>
                <td><input type="text" name="jtitle" id="jtitle" tabindex="10" maxlength="70"/>                </td>
                <td class="loginfont"><strong>&nbsp;&nbsp;Comments </strong>                </td>
                <td>&nbsp;                </td>
              </tr>
              <tr>
                <td  height="28"><span class="loginfont">&nbsp;<span class="error">*</span><strong> Position Level</strong></span>                
                </td>
                <td><input type="text" name="poslevel" id="poslevel" tabindex="11" maxlength="10"/>                
                </td>
                <td colspan="2" rowspan="3">&nbsp;&nbsp;
                <textarea name="commenttxtbox" id="commenttxtbox" cols="30" rows="5" tabindex="18" wrap="soft" ></textarea>
                </td>
              </tr>
              <tr>
                <td height="28"><span class="loginfont">&nbsp;<span class="error">*</span><strong> Effective Date</strong></span>                
                </td>
                <td><input type="text" name="effdate" id="effdate" tabindex="12" maxlength="11"/>                </td>
              </tr>
              <tr>
                <td>&nbsp;                </td>
                <td>&nbsp;                </td>
              </tr>
  			  <tr>
                <td height="19" colspan="4">
                  <div class="error" id="valerror3"> </div>                
                </td>
              </tr>
              <tr>
                <td align="right" colspan="2" nowrap="nowrap">
                  <input type="submit" name="add" id="add" value=" ADD " tabindex="19" />&nbsp;&nbsp; &nbsp;
                  <input type="submit" name="edit" id="edit" value=" EDIT " tabindex="20" />&nbsp;&nbsp; &nbsp;
                  <input type="submit" name="delete" id="delete" value="DELETE" tabindex="21" />&nbsp;&nbsp;&nbsp;&nbsp;                </td>
              <td colspan="2" nowrap="nowrap" align="center">
                    <input type="submit" name="save" id="save" value=" Save " tabindex="22" /> &nbsp;&nbsp;&nbsp;
                  <input type="submit" name="cancel" id="cancel" value="Cancel" tabindex="23" />&nbsp;&nbsp;&nbsp;                </td>
              </tr>
  			  <tr>
                <td height="23" colspan="4">
                  <div class="error" id="valerror3"> </div>                
                </td>
          </tr>
          </table>    	
    </td>
    <td width="4" >&nbsp;</td>
  </tr>
  <tr>
    <td colspan="5">
    
<!--      Insert the HMTL table below and the heading above 			-->
<!--    	<div class="accountsearchlist">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#FFFFFF" class="tablefont" >
            
-->
            
<!--            </table>
        </div>
-->
    </td>
  </tr>
<!--  <tr>
    <td colspan="5" align="center">&nbsp;</td>
  </tr>-->
  <tr>
    <td colspan="5">
	<table width="97%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
   		<td class="tableheading" height="28"><p><strong>Workforce  Member ID Search HISTORY</strong></p></td>
  	</tr>
  	<tr>
   		<td >
        <div class="accountsearchlist">
           <table width="100%" border="1px" cellspacing="0" cellpadding="2" class="tablefont">
             <tr>
               <td width="6%">&nbsp;</td>
               <td width="8%"><div align="center"><strong>Effective Date</strong></div></td>
               <td width="8%"><div align="center"><strong>Last Name</strong></div></td>
               <td width="8%"><div align="center"><strong>First Name</strong></div></td>
               <td width="9%"><p align="center"><strong>Middle Initial</strong></p>             </td>
               <td width="5%"><div align="center"><strong>Service</strong></div></td>
               <td width="5%"><div align="center"><strong>Tenure</strong></div></td>
               <td width="11%"><div align="center"><strong>Department</strong></div></td>
               <td width="8%"><div align="center"><strong>Job Title</strong></div></td>
               <td width="10%"><div align="center"><strong>Position Level</strong></div></td>
               <td width="22%"><div align="center"><strong>Comments</strong></div></td>
             </tr>
             <tr>
               <td align="center"><input type="radio" name="radio" id="r1" value="r1" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>
             <tr>
               <td align="center"><input type="radio" name="radio" id="r1" value="r1" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>         
             <tr>
               <td align="center"><input type="radio" name="radio" id="r1" value="r1" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>         
             <tr>
               <td align="center"><input type="radio" name="radio" id="r1" value="r1" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>         
             <tr>
               <td align="center"><input type="radio" name="radio" id="r1" value="r1" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>         
             <tr>
               <td align="center"><input type="radio" name="radio" id="r1" value="r1" /></td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
               <td>&nbsp;</td>
             </tr>
           </table>
           </div>
         </td>
      </tr>
    </table>
	</td>
  </tr>
  <tr>
   <td colspan="5">
       	<table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td width="9%" height="85">&nbsp;</td>
            <td width="15%" nowrap="nowrap">
            <fieldset>
                  <legend class="loginfont">Navigation</legend>
                  <br />
                    <input type="submit" name="mainmenu" id="mainmenu" value="Main Menu" tabindex="24" />&nbsp;&nbsp;
                    <input type="submit" name="logout" id="logout" value="Log out" tabindex="25" />
                  <br />  
                </fieldset>
            </td>
            <td width="76%">&nbsp;</td>
          </tr>
    	</table>
   </td>
  </tr>
</table>
</form>
</body>
</html>

Open in new window

0
Comment
Question by:sanrich
  • 4
  • 3
7 Comments
 
LVL 20

Accepted Solution

by:
chaitu chaitu earned 500 total points
ID: 22747680
In WorkForcememberIDSearch if user enter data in any one of thefields(Workforce ID,Last Name,First Name) and select any one of the radio button(Full Name,Workforce ID,Service,Role) and click Find button ,the data should be displayed in Workforce Member ID Search HISTORY.Is it Right?

If that is the case use one servlet.there open the database connection in servelt and put all the data in one object and put the data in request object and send it back to this jsp?
0
 

Author Comment

by:sanrich
ID: 22748010
NO, He will only select radio button and we have display its deatils in history grid.
0
 
LVL 20

Assisted Solution

by:chaitu chaitu
chaitu chaitu earned 500 total points
ID: 22748172
user select radio button  in In WorkForcememberIDSearch and click Find button.am i right?
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

Author Comment

by:sanrich
ID: 22748450
No, just select radio button and not find button. We have to query DB .
0
 
LVL 20

Expert Comment

by:chaitu chaitu
ID: 22748503

call onchange function when user click radio button.
 
<input type="radio" name="radio" id="radio" value="radio" onChange="ex()" />
 
	function ex()
		{
			document.forms[0].action="/SomeServlet?operation=getFullNameFromDB"
			document.forms[0].submit();
 
		}
 
SERVLET
*********
if(request.getParameter("operation").equals("getFullNameFromDB"))
{
 
DataSource ds= (DataSource) context.lookUp("java:oraclePool");
 
Connection con = ds.getConnection(); 
PreparedStatement stmt =con.preparedStatement();
ResultSet rs= stmt.createQuery("select * from table where table='fullname'";
ArrayList al = new ArrayList();
while(rs.next())
{
Customer c =new Customer();
c.setEffectiveDate(rs.getDate(1))
c.setLastname(rs.getString(2))
c.setFirstName(rs.getString(3));
...
al.add(c);
}
 
request.setAttribute("results",al);
}
 
 
in jsp print these values in History grid.
 
ArrayList results = (ArrayList)request.getAttribute("results");
 
for(int i=0;i<results.size();i++)
{
   (Customer) c =(Customer)results.get(i);
print these values in the history grid jsp
}

Open in new window

0
 

Author Comment

by:sanrich
ID: 22753976
Thanks this is working but, there is problem it works fine when I click on twice on radio button but not first time. i.e. suppose I have three radio button. When I select first one nothing happens then when I select second one at that time first one gets called. same it with other buttons like when I click 3rd then nothing happens and when I click first then 3rd is called. Here whats I did

<script type="text/javascript">
      var formInUse = false;
      function setFocus()
            {
                   if(!formInUse) {
                                                  document.add.lname.focus();
                                           }
            }

       function triggerval()
            {
                  document.forms[0].action="/jsp/S1Controller.jsp?operation=getval";
                  document.forms[0].submit();
 
            }

</script></head>


In in JSP FORM

 <tr>
                    <td width="6%" align="center"><input type="radio" name="wfradio" id="radio" value="<%= strValue %>"  
                               onChange="triggerval()"   /></td>
                    <td width="18%"><%= strScreenName[0] %></td>
                    <td width="24%"><%= strScreenName[1] %></td>
                    <td width="18%"><%= strScreenName[2] %></td>
                    <td width="34%"><%= strScreenName[3] %></td>
                </tr>
0
 
LVL 20

Assisted Solution

by:chaitu chaitu
chaitu chaitu earned 500 total points
ID: 22754806
insteadof onChange use onClick ;

<input type="radio" name="wfradio" id="radio" value="<%= strValue %>"  
                               onClick="triggerval()"   />
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question