473,383 Members | 1,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

want data base connection in focus lost of a textbox in the table

i wrote a code in jsp to create dynamic table..the problem is i need data base connection when cursor moves from one cell to other...
eg...when i enter product id in the first cell, the product name and its rate should come in the next two cells...it should take from the data base...

it's my code........

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
  2. "http://www.w3.org/TR/html4/loose.dtd" > 
  3. <%@ page import="java.sql.*" %> 
  4. <%@ page import="java.io.*" %> 
  5.  
  6. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  7.  
  8. <head>
  9.   <title></title>
  10. <script language="JavaScript" type="text/javascript">
  11. /*<![CDATA[*/
  12.  
  13.     var i=1,j=0,k=0,tot=0,vat=0,totrow=0;
  14. function Add(id){
  15.  var id1='ta'+i;
  16.  var id2='tb'+i;
  17.  var id3='tc'+i;
  18.  var id4='td'+i;
  19.  var id5='te'+i;
  20.  var table=document.getElementById(id);
  21.  var tbody=table.getElementsByTagName('TBODY')[0];
  22.  var newrow=tbody.appendChild(table.rows[0].cloneNode(true));
  23. // newrow.getElementsByTagName('SELECT')[0].selectedIndex=0; for combobox
  24.  newrow.getElementsByTagName('INPUT')[0].value='';
  25.  newrow.getElementsByTagName('INPUT')[0].id=id1;
  26.  newrow.getElementsByTagName('INPUT')[0].name=id1;
  27.  
  28.  newrow.getElementsByTagName('INPUT')[1].value='';
  29.  newrow.getElementsByTagName('INPUT')[1].id=id2;
  30.  newrow.getElementsByTagName('INPUT')[1].name=id2;
  31.  
  32.  newrow.getElementsByTagName('INPUT')[2].value='';
  33.  newrow.getElementsByTagName('INPUT')[2].id=id3;
  34.  newrow.getElementsByTagName('INPUT')[2].name=id3;
  35.  
  36.  newrow.getElementsByTagName('INPUT')[3].value='';
  37.  newrow.getElementsByTagName('INPUT')[3].id=id4;
  38.  newrow.getElementsByTagName('INPUT')[3].name=id4;
  39.  
  40.  newrow.getElementsByTagName('INPUT')[4].value='';
  41.  newrow.getElementsByTagName('INPUT')[4].id=id5;
  42.  newrow.getElementsByTagName('INPUT')[4].name=id5;
  43.  
  44.  newrow.getElementsByTagName('INPUT')[5].checked=false;
  45.  i++;
  46. }
  47.  
  48. function Remove(id,nme){
  49.  var table=document.getElementById(id);
  50.  var rows=table.rows;
  51.  for (var remove=[],zxc0=0;zxc0<rows.length;zxc0++){
  52.   var cb=rows[zxc0].getElementsByTagName('INPUT')[5];
  53.   if (cb&&cb.name==nme&&cb.checked){
  54.    remove.push(rows[zxc0]);
  55.   }
  56.  }
  57.  if (remove.length==rows.length) return alert('U cant remove all rows');
  58.  for (var zxc1=0;zxc1<remove.length;zxc1++){
  59.   remove[zxc1].parentNode.removeChild(remove[zxc1]);
  60.  }
  61. }
  62.  
  63. /*
  64. function Remove(id){
  65.  var table=document.getElementById(id);
  66.  var rows=table.rows;
  67.  for (var zxc0=0;zxc0<rows.length;zxc0++){
  68.   if (rows[zxc0].getElementsByTagName('INPUT')[5].checked){
  69.    rows[zxc0].parentNode.removeChild(rows[zxc0]);
  70.    zxc0--;
  71.   }
  72.  }
  73. }
  74. */
  75. function showText(tid,bid)
  76. {
  77.     var txt=document.getElementById(tid);
  78.     var but=document.getElementById(bid);
  79.     txt.type="textbox";
  80.     but.type="button";
  81.     //but.onclick="hideText()";
  82.     alert("Please Enter Purchase.Order.No and click OK");
  83. }
  84. function hideText(tid1,bid1)
  85. {
  86.     var txt1=document.getElementById(tid1);
  87.     var but1=document.getElementById(bid1);
  88.     txt1.type="hidden";
  89.     but1.type="hidden";
  90.  
  91. }
  92. function test(tt0)
  93. {
  94.     var dd='ta'+j;
  95.     var ttxt0=document.getElementById(tt0);
  96.     var ttxt1=document.getElementById(dd);
  97.     var ppnam=ttxt1.value;
  98.     //var ppnam=ttxt1.value;
  99.     ttxt0.value=ppnam;
  100.     j++;
  101.  
  102. }
  103. function test5(tt5)
  104. {
  105.     var dd3='tc'+k;
  106.     var dd4='td'+k;
  107.  
  108.     var ttxt5=document.getElementById(tt5);
  109.     var ttxt3=document.getElementById(dd3);
  110.     var ttxt4=document.getElementById(dd4);
  111.  
  112.     var num2=ttxt4.value;
  113.     var num1=ttxt3.value;
  114.  
  115.     var val=0;
  116.     val=parseFloat(num1) * parseFloat(num2);
  117.     ttxt5.value=val;
  118.     k++;
  119. }
  120. function cal(id)
  121. {
  122.     var table=document.getElementById(id);
  123.     var rows=table.rows;
  124.     for (var zxc0=0;zxc0<rows.length;zxc0++)
  125.      {
  126.         //tot=tot+5;
  127.         tot=parseFloat(tot)+parseFloat((rows[zxc0].getElementsByTagName('INPUT')[4].value));
  128.         totrow++;
  129.      }
  130.      vat=parseFloat(tot/12.5);
  131.      document.product.vate.value=vat;
  132.      document.product.total.value=parseFloat(vat+tot);
  133.      document.product.rcount.value=totrow;
  134.      vat=0;
  135.      tot=0;
  136.      totrow=0;
  137. }
  138. </script>
  139.  
  140. <body>
  141.  
  142. <form name="product" action="mynew.jsp" method="get">
  143. <table id="head" border="1">
  144. <tbody>
  145. <tr><td colspan="50"><b>&nbsp;Product Id&nbsp;&nbsp;&nbsp;</b></td><td colspan="50"><b>&nbsp;Product Name&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;</b></td><td colspan="50"><b>&nbsp;Quantity&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td><td colspan="30"><b>&nbsp;Rate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</b></td><td colspan="30"><b>&nbsp;Value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></b></td>
  146.   </tr>
  147. </tbody>
  148. </table>
  149. <table id="tst" border="1">
  150. <tbody>
  151.   <tr>
  152.     <td>
  153.     <input name="ta0" type="textbox" size="10" id="ta0"/>
  154.     <input name="tb0" type="textbox" size="30" id="tb0" onfocus="test(id);"/>
  155.     <input name="tc0" type="textbox" size="10" id="tc0"/>
  156.     <input name="td0" type="textbox" size="10" id="td0"/>
  157.     <input name="te0" type="textbox" size="10" id="te0" onfocus="test5(id);" readonly/>
  158.     <input type="checkbox" name="bb[]" id="cbox"/></td>
  159.   </tr>
  160. </tbody>
  161. </table>
  162. <input type="button" name="" value="Add" onclick="Add('tst');"/>
  163. <input type="button" name="" value="Remove" onclick="Remove('tst','bb[]');"/>
  164. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  165. <input name="txt1" type="hidden" id="textid" size="10"/>
  166.  
  167. <input name="" value="OK" type="hidden" id="buttonid" size="10" onclick="hideText('textid','buttonid');"/>
  168. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  169. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  170. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  171. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  172. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  173. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  174.  
  175. <input type="button" value="calculate" onclick="cal('tst');"/>
  176. <br>
  177. <br>
  178. Vat:&nbsp;&nbsp;
  179. <input type="textbox" name="vate"/>
  180. <br>
  181. <br>
  182. Total:
  183. <input type="textbox" name="total"/>
  184. <br>
  185. <br>
  186. <input type="button" name="" value="Edit" onclick="showText('textid','buttonid');"/>
  187. <input type="submit" name="" value="Save"/>
  188. <br>
  189. <br>
  190. <input type="textbox" name="rcount"/>
  191. <%
  192.  
  193. %>
  194. <br>
  195.  
  196. <%
  197.  int count=0;
  198.   try { count = Integer.parseInt(request.getParameter("rcount")); 
  199.   }
  200.     catch (Throwable t) { }
  201.  
  202.  String pid[]=new String[count];
  203.  String pnam[]=new String[count];
  204.  String qtyt[]=new String[count];
  205.  String rate[]=new String[count];
  206.  String value[]=new String[count];
  207.  String vatt=null,tot=null;
  208.  
  209. %>
  210.  
  211. <input type="textbox" name="rnum" value=<%=count%>>
  212.  
  213. </form>
  214.  
  215. </body>
  216. </head>
  217. </html>
Sep 22 '08 #1
1 2438
r035198x
13,262 8TB
Please use code tags when posting code.
What you need is usually done using AJAX these days.
Sep 23 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Qumer Mumtaz | last post by:
h I am using a datagrid control. I am displaying some controls like Date Time picker, combo boxes, ect in some cells.When a particuler cell is got focus the control is displayed and user select the...
12
by: Mike | last post by:
I'm calling a component to get my data. The component is returning a dataset. I need to populate text boxes on my aspx page with the data within the datalist. Where can I find an example that...
6
by: ruben | last post by:
Hi: I'm running a large database on PostgreSQL 7.1.3. 20 days ago the database failed with a threatening and not too descriptive error like: pg_exec() query failed: server closed the...
0
by: pd123 | last post by:
I'm new to C# and .net and I'm trying to create a form that will register users in a sql server database. I have the following code but when I run the code I get an error " The name 'Peter' is...
1
by: Praveena.Alapati | last post by:
Hi, There is a tab control on a page with multiple tabs and handful of controls in each tab. The way it's rendered in html (like grid etc..) is in table format in tablerows and cells. On...
4
by: itsnidhu | last post by:
Hi this is nidhi from india, Since last 2 days i am facing a problem in asp.net code. The data base connection is done correctly as i can select the data from the database. But i can not insert...
0
by: =?Utf-8?B?Qw==?= | last post by:
Hi, I have a series of textboxes on an aspx page. These textboxes are within an UpdatePanel. On the OnTextChanged Event of each textbox I do some calculations in my codebehind and update...
11
by: karen987 | last post by:
I have a web page which used to work fine until i added a rich text editor. the pages are in ASP and it is a news weblog, with a comments section where people click the headline of a comment and...
1
by: ravikumar2007 | last post by:
I am working with .NET 3.5 framework within an WPF application. I have a windows application where for a textbox, I have defined the lost focus event. I need to call the Focus() method of any other...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.