on 02-07-2006 2:13 PM
Hi,
Can anyone send me the code to generate date and Id automatically in the textboxes.im using SAP NWDS.Should I write the code 4 this in the jsp or Servlet?
With Regards,
Jais.
Hi Jaisamma,
let me know , what u mean with this ID?.
In JSP , you have two options,
1) You can use javascript to find out the Current date and format it.
2) You can use java code itself to find out current days date and format it.
In JSP
Using javascript
-
<b><html>
<script language="javascript">
function onLoadin()
{
d = new Date();
var date = d.getDate();//For getting date range 1-31
var month = d.getMonth()+1;//Value range 0-11
var year = d.getYear();
/*
for formatting it to presentable format
*/
var sydate = date + "/" + month + "/" +year;
document.myForm.datum.value= sydate;
}
</script>
<body onLoad="onLoadin()">
<form name="myForm">
<input name="datum" type="text" size="13" maxlength="10"/>
</form>
</body>
</html>
go through this.
http://www.javascriptkit.com/jsref/date.shtml
</b>
this contains details of javascript date object
http://www.w3schools.com/jsref/jsref_obj_date.asp
Using java code
-
<%@ page import="java.text.*" %>
<%@ page import="java.util.*" %>
<%
Format formater = new SimpleDateFormat("dd/MM/yyyy");
Date syDatum = new Date();
<td><font SIZE="1">Date</FONT></td>
<td align="left"><i><%=formater.format(syDatum)%></i></td>
%>
let me know , is your application using any database for storing the ID ?.
Regards
Kishor Gopinathan
Message was edited by: Kishor Gopinathan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kishor,
Thanks for ur help. but can u plz tell if i can write this in the following way also since in this format i did my whole jsp..im a beginner tats y im asking..
<%language="java" %>
<html>
<body>
<form>
<script type="text/javascript">
document.form[0].datum.value= Date();
</script>
<td>
Datum
</td>
<td
<width="10">
</td>
<td
align="centre">
<input
name="datum"
type="text"
size="13"
maxlength="10"/>
</td>
</body>
</form>
</html>
And by ID i meant wot v r using as the primary key.I want that The id will be automaically generated while v use the GUI.it should not be given manually.if u didnt get wot i meant plz let me know..waiting for ur reply..:-)
With regards,
Jaisamma
hi,
the bellow piece of code should work for u..
<script type="text/javascript">
<%Date now = new Date()%>
document.form[0].datum.value=
<%=DateFormat.getDateInstance().format(now))%>
</script>
Since the Date method is of java's ,you have to place them in scriptlet and when it reaches the browser (<%=... %>) is replaced with the actual date value..
Regarding the ID , the best way is to generate the id from the database. If u want to avoid using database and still want to create id's dynamically , i can suggest some methods(which may not be fool proof.).
regards,
arul sekar
Hai jaisamma,
for what purpose r u using this IDs?
r u storing this IDs in any data base?.
r u reusing this IDs in future or just for one time display?.
if u r using this for one time purpose , then we can take the current time inmillis . its unique.. but for later use u have to store it somewhere.
Regards
Kishor Gopinathan
Hi Jaisamma ,
one simple way to generte id is , u can take the
System.currentTimeMillis()).toString() method to get the current time in millis . it will be unique always.(but u have to give proper data lenght for storing this.
another way is , u can get the max value from the data base itself for particular column.
SELECT MAX(<ID>) FROM <table Name>.
Edited.
-
that depend upon the database.
u can use long ..
just hav a look at this
http://edocs.bea.com/wli/docs81/rdbmseg/datatypes.html#1064181
Regards
Kishor gopinathan
Message was edited by: Kishor Gopinathan
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.