Hey hi all,
I am new to jsp,servlets .. i am doing a small project on employee database management.
In this I have a form which has various fields. And also buttons for add,delete,update,next and previous. Now what I want is I click on previous it should retreive values from database .. its easy but then i want it to be displayed in the fields present in the form itself.

<input type="submit" value=" PREVIOUS" name="PREVIOUS" onClick="submitForm(this)"/>

this is calling the previous which is

else if(clickedbutton.name =="PREVIOUS")
		{
		//	String s1=request.getParameter("EmployeeID");
		//	int i = Integer.parseInt(s1)-1;
		//	document.registrationform.EmployeeID.value='i';
		//	document.registrationform.Name.value;
			
		}

now this is wat i wrote which is not working.
can u please help me go ahead.
thanks

when you submit the form, what is the action attribute. Maybe you need when each button is clicked to submit to a different jsp page. From there you will need to retrieve the data from request:

<a href="retreive.jsp?EmployeeID=<%=previousId%>">Previous</a>

<a href="retreive.jsp?EmployeeID=<%=nextId%>">Next</a>

You will also need to post more code and stop confusing java with javascript

form contains the information fields and after that whole code is here

table>
 <TR>
 <TD>  <input type="submit" value="  SAVE" name="SAVE" onClick="submitForm(this)"/> </TD>
 <TD>  <input type="submit" value="   ADD" name="ADD" onClick="submitForm(this)"/> </TD>
 <TD>  <input type="submit" value="UPDATE" name="UPDATE" onClick="submitForm(this)"/> </TD>
 <TD>  <input type="submit" value="DELETE" name="DELETE" onClick="submitForm(this)"/> </TD>
 
 </TR>
 
 <TR>
  <TD>  <input type="submit" value="FIRST" onClick="submitForm(this)"/> </TD>
  <TD>  <input type="submit" value=" PREVIOUS" name="PREVIOUS" onClick="submitForm(this)"/> </TD>
  <TD>  <input type="submit" value=" NEXT" onClick="submitForm(this)"/> </TD>
  <TD>  <input type="submit" value=" LAST" onClick="submitForm(this)"/> </TD>
</TR> 
 </table>
 </form>
 
 <script type="text/javascript">

	function submitForm(clickedbutton)
	{	
		
		if(clickedbutton.name=="SAVE")
		{
			document.registrationform.action="Save";
		}
			
		else if(clickedbutton.name=="ADD")
		{
			//will come to the same page (all fields cleared),after incrementing ID by 1.
			//how to set table id???
			//var oRows = document.getElementById("employee").rows.length;
			//document.registrationform.EmployeeID.value=++orows;
			document.registrationform.Name.value="";	 	
			document.registrationform.Phone.value="";
			document.registrationform.EmailID.value="";
			document.registrationform.Address.value="";
			document.registrationform.EducationalQualifications.value="";
			document.registrationform.Department.value="...";
			
		}

		else if(clickedbutton.name =="UPDATE")
		{	
			//every field which were disabled .. will be enabled xcept ID
			//document.registrationform.EmployeeID.disabled;
			//document.registrationform.Name.disabled; 
			alert("UPDATE");
			document.registrationform.action="Update";
		}

		
		else if(clickedbutton.name =="DELETE")
		{
			ID = registrationform.elements["EmployeeID"].value;
	        //Employeed = registrationform.elements["Employeed"].value;
			document.registrationform.action="/Employee/Delete";
		}

		
		else if(clickedbutton.name =="NEXT")
		{
			document.registrationform.action="First.jsp";
		}
		else if(clickedbutton.name =="FIRST")
		{
			alert("FIRST");
			document.registrationform.action="First.jsp";
		}
		else if(clickedbutton.name =="LAST")
		{
			alert("LAST");
			document.registrationform.action="Last.jsp";
		}
		
		else if(clickedbutton.name =="PREVIOUS")
		{
		//	String s1=request.getParameter("EmployeeID");
		//	int i = Integer.parseInt(s1)-1;
		//	document.registrationform.EmployeeID.value='i';
		//	document.registrationform.Name.value;
document.registrationform.action="Previous.jsp";

			
		}
	}
	
	</script>
</body>
</html>

now this is the code , and i cant use hyperlink in a javascript in which i have written the submitform method. from the Previous' part of the method if even i go to a servlet then how will i access the form again to put the retrieve values in them.

You can read the employee id and set it to a javascript variable like this:

var empId = "<%= request.getParameter("EmployeeID") %>";

I don't know your logic but subtracting the id by one will not always get you the previous employee. You can not expect that the ids will always be sequential.
When you go to that page you need a way to know the previous and next id.

You need to know all the ids from the database when you go to that page for the first time. Then when you go next or previous, when the page loads, you have the current id, so just find the previous and next, and use those values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.