Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

open the selected row values in the edit mode in new form using javascript

 
shriganesh kakade
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after clicking the select button in front of particular row, i want to open the new form containing the selected row values in the edit mode.
and the rows are taken from the database table using result set.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Post here what you have done so far. Your solution is needed to let the people help you.
 
shriganesh kakade
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have used one hidden field for each row in which the id of that particular will be stored and then after clicking Select button that id is passed to one function.
in that function, id will be sent to the next page in which i want to edit that values.
But the problem is i get all the ids from the result set in the next page and values in the form to be edited are from the first row only even if i selected second row.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please post the code.
Thank you
 
shriganesh kakade
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<% while(rs.next()){%> <%=rs.getString("Emp_name")%><%=rs.getString("Email_id")%><%=rs.getString("Ph_no")%><input type="hidden" name="id" value="<%=rs.getString("Emp_id")%>"><input type="submit" value="Select" onclick="editRecord(<%=rs.getString("Emp_id")%>)"> <%}%>


after that function is:

editRecord(id){
var f = document.form;
f.method="post";
f.action='next.jsp?id='+id;
f.submit();
}

and in next.jsp:

request.getParameter("id");
after getting the id, the actual data related to corresponding id is to be retrieved.

Thank you..
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


One problem is that hidden input is overwritten.

Debug your javascript code, and see what id value is passed to your javascript function editRecord when you click on submit button.

 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better, you don't even need the hidden id value, you can delete it.

I mean delete the following line , it's useless



Another thing.
You have a submit button and in your javascript function you call submit again on your form. I am not sure but i think you could have bad surprises there.
 
shriganesh kakade
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Garofalo wrote:Better, you don't even need the hidden id value, you can delete it.


<input type="hidden" name="id" value="<%=rs.getString("Emp_id")%>">


then how the next pages will get the id?

Thank you..
 
shriganesh kakade
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Garofalo wrote:Better, you don't even need the hidden id value, you can delete it.

I mean delete the following line , it's useless



Another thing.
You have a submit button and in your javascript function you call submit again on your form. I am not sure but i think you could have bad surprises there.


Yes it is correct saying, but the problem is that when i used the input type as button instead of submit, it does not perform any action, even after clicking that button.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So why did you use a query String in your action?

You can keep your hidden input written like these



And in javascript editRecord function you will write


 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Yes it is correct saying, but the problem is that when i used the input type as button instead of submit, it does not perform any action, even after clicking that button.


May i see how you wrote the form tag?
Did you give it a name or an id?
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nicola Garofalo wrote:

You can keep your hidden input written like these




Sorry i didn't tell you to put the hidden tag outside while loop. You just need one.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic