File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes HTML, CSS and JavaScript and the fly likes issue with returning from a function on a onClick event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "issue with returning from a function on a onClick event" Watch "issue with returning from a function on a onClick event" New topic

issue with returning from a function on a onClick event

Ashwin venkatesh

Joined: Oct 16, 2006
Posts: 7
Hello Every one,

I am facing a problen in retrieving data from the database and displaying the same in there respective textboxes in a jsp page on a onClick event. ie i have button Next i call a javascript function in a jsp page with some textfields. when i press the Next button the next record in the database should be displayed. My code is as follows...

ResultSet rs1 = null;
rs1= stmt.executeQuery("select * from custtable");


function next_rec(kform)
var xx = document.usrreg.next_button.value;
var zz = xx.toString();

if(xx == 'Next')


int RECNO = rs1.getInt("recordno");
String DCODE = rs1.getString("dcode");
String CUSTCODE = rs1.getString("custcode");
String CUSTNAME1 = rs1.getString("custname");
String ADDR = rs1.getString("addr");
String CITY = rs1.getString("city");

document.usrreg.recordno.value = '<%=rno%>';
document.usrreg.dcode.value = '<%=DCODE%>';
document.usrreg.custcode.value = '<%=CUSTCODE%>';
document.usrreg.custname.value = '<%=CUSTNAME1%>';
document.usrreg.addr.value = '<%=ADDR%>'; = '<%=CITY%>';



}//try ends
catch(Exception e)
<form name="usrreg">


<tr><td>Record No</td><td <input type="text" name="recordno" readonly value=<%= count%>></td>

<tr><td>Dealer Code</td><td><input type="text" name="dcode" readonly value= <%= delcode%>></td>

<tr><td>Customer Code</td><td><input type="text" name="custcode" readonly value= <%= cust_code%>></td>

<tr><td>Customer Name</td><td><input type="text" name="custname" onchange="return customer_name(this.form,'1')"></td>

<tr><td>Address</td><td><textarea name="addr" rows="5" cols="15"> </textarea>

<tr><td>City</td><td><input type="text" name="city" onchange="return city_name(this.form)"></td>


<tr><td> <input type="button" value="Next" onklick="next_rec(this.form)" name="next_button"></td>
i have changed to onklick because problem in posting my request

the values are displayed only once when the form is loaded, for another onClick event it is not displaying the values.

pls help me at the earliest..
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
I think you need to read this article [] that bear wrote to understand how JavaScript and JSP code actually works.

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63532

Link to article.

Not to mention that doing SQL access in a JSP is pretty much universally considered an extremely poor practice.
[ August 08, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: issue with returning from a function on a onClick event
It's not a secret anymore!