472,353 Members | 1,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 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 2361
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...
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...
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: ...
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...
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...
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...
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...
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...
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

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.