aspose file tools*
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
Author

issue with returning from a function on a onClick event

Ashwin venkatesh
Greenhorn

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");
//rs1.first();

%>


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

if(xx == 'Next')
{

<%
try

{
rs1.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%>';

document.usrreg.city.value = '<%=CITY%>';

<%

if(rs1.isAfterLast())
rs1.first();


}//try ends
catch(Exception e)
{
System.out.println(e.toString());
}
%>
}
}
<form name="usrreg">

<table>

<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>

</table>

<tr><td> <input type="button" value="Next" onklick="next_rec(this.form)" name="next_button"></td>
</tr>
</form>
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
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
I think you need to read this article [http://www.javaranch.com/journal/200510/Journal200510.jsp#a1] that bear wrote to understand how JavaScript and JSP code actually works.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

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] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: issue with returning from a function on a onClick event
 
Similar Threads
In the messages module reply is not working
cookies problem
text field validation
two dropdown menus
Sending Email from jsp page