I have a jsp page In that there is a combobox & some textbox.Combobox contains all the username.which is stored in the xml file.I know the first UserName from the combobox.Suppose the first name is ' John'. Its userId is ' 1'. When I open the page.The comboBox has all the values. the first Username 'John ' will be selected. At that time the userId is showing null But it has to show userid '1'. If I change the userName then Onchange event will fire & then its userId will come in the userid textbox.I wrote "document.form1.submit() " on Onchange event of select tag.I tried to give same event on onLoad of body & form .But nothing happenes.Can anyone tell me what to do.I want the userId of the first element in the UserId textbox when page is loaded.
<input type = submit value = Submit onclick="txtDate('LeaveTo', 'LeaveFrom','NoOfDays');">
</td>
<td>
</td>
</tr>
</table>
Code for CustomTag for select : ----------
public int doStartTag() throws JspException {
StringBuffer sb = new StringBuffer();
JspWriter out = pageContext.getOut();
sb.append("<td><b><font size=3 face=Times New Roman > " + name + "</font><//b></td><td><select name ="+name);
sb.append(" onChange=" + changeEvent );
sb.append(">");
sb.append("<td><b><font size=3 face=Times New Roman > " + name + "</font><//b></td><td><select name ="+name);
sb.append(" onChange=" + changeEvent );
sb.append(">");
The valueObject is returning null. If I change any name then valueObject will have that value. How to get the userId of the selected value on the pageLoad
now run ur jsp code oon server and then when u see the page displayed where it actually shows a null value, take a look at the page source and post that here....
<script language="javascript">
function txtDate(ldate,ndate,noofdays){
var toDate=new Date(document.getElementById(ldate).value)
var fromDate=new Date(document.getElementById(ndate).value)
var one_day=1000*60*60*24
if(form1.halfDay.checked )
{
var days=(Math.ceil((toDate.getTime()-fromDate.getTime())/(one_day))+1)- 0.5
}
else
{
var days=Math.ceil((toDate.getTime()-fromDate.getTime())/(one_day))+1
}
document.getElementById(noofdays).value=days
}
</script>
<center>
<th bgcolor="#CCCCFF" colspan="2">
<font size="6"><b><u>Leave Application Form</u></b></font>
</th>
<br><br><br><br><br>
<body bgcolor =cccccc >
<form name="form1" method="post" >
<table border=0 cellpadding="4" cellspacing="3">
<tr>
<td>
<b><font size=3 face=Times New Roman > LeaveId</font><//b><td><input type = text name =LeaveId value="5"readonly ><br></td>
</td>
</tr>
<tr>
<td><b><font size=3 face=Times New Roman > UserName</font><//b></td><td><select name =UserName onChange=document.form1.submit()><option value="Ann">Ann</option><option value="Mary">Mary</option><option value="Tinu">Tinu</option><option value="Minu">Minu</option></select><br>
<td>
</td>
<td><b>UserId</b></td>
<td>
<input type="text" name="UserId" value="null" readonly />
</td>
</tr>
<tr>
<td>
<b><font size=3 face=Times New Roman > LeaveFrom</font><//b><td><input type = text name =LeaveFrom value="03-14-2006"readonly ><br></td>
</td>
<td>
<img name="calander" src="/LeaveApplication/Framework/images/calendar.gif" width="16" height="15" onClick="javascript:show_cal(LeaveFrom,1)" />
</td>
<td>
<b><font size=3 face=Times New Roman > LeaveTo</font><//b><td><input type = text name =LeaveTo value="03-14-2006"readonly ><br></td>
</td>
<td>
<img name="calander" src="/LeaveApplication/Framework/images/calendar.gif" width="16" height="15" onClick="javascript:show_cal(LeaveTo,1)" />
</td>
<td>
<input type=CHECKBOX name="halfDay" value="HalfDay" onclick="txtDate('LeaveTo', 'LeaveFrom','NoOfDays');"><b>Half Day</b>
</td>
</tr>
<tr>
<td>
<b><font size=3 face=Times New Roman > NoOfDays</font><//b><td><input type = text name =NoOfDays value="1"readonly ><br></td>
</td>
<td>
<td><b><font size=3 face=Times New Roman > Reason</font><//b></td><td><textarea name =Reason value=""></textarea><br></td>
<script language="javascript">
function txtDate(ldate,ndate,noofdays){
var toDate=new Date(document.getElementById(ldate).value)
var fromDate=new Date(document.getElementById(ndate).value)
var one_day=1000*60*60*24
if(form1.halfDay.checked )
{
var days=(Math.ceil((toDate.getTime()-fromDate.getTime())/(one_day))+1)- 0.5
}
else
{
var days=Math.ceil((toDate.getTime()-fromDate.getTime())/(one_day))+1
}
document.getElementById(noofdays).value=days
}
</script>
<% int flag = 0; %>
<center>
<th bgcolor="#CCCCFF" colspan="2">
<font size="6"><b><u>Leave Application Form</u></b></font>
</th>
<br><br><br><br><br>
<%System.out.println(" leave data vo user name : " + leavedata.getUserName()); %>
<body bgcolor =cccccc >
Bookmarks