lilyyan
asked on
how to get the parameter values, should the parameter names is assigned danamically ?
hello,
in a jsp page, there is a list of records retrieved from a database. and for each record i want to pass a ID value which is the primery key.
in jsp something like:
-------------------------- -----
<form >
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get (i).toStri ng() %>" />
<a href="#" onClick="submitThisForm(3) ">
<img src="editable.gif" border="0" alt="Edit profile"></a>
<% } %>
</form>
-------------------------- ----------
for each record, there is an unique ID value, whenv user click the "edit" image, the parameter "memberIDNumber" will be submited to testID.java
my questions is:
the error i got is: no matter i click which "edit" image of these printed records, the value of "memberIDNumber" i retrived from testID.java is always same
here, i'm using a same valriable name: "memberIDNumber" in the input field. is ithis the reason for the error? it seems it only pased the last element (ID value) in the memberIDList.
Thank you so much for your reply,
lilyyan
in a jsp page, there is a list of records retrieved from a database. and for each record i want to pass a ID value which is the primery key.
in jsp something like:
--------------------------
<form >
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get
<a href="#" onClick="submitThisForm(3)
<img src="editable.gif" border="0" alt="Edit profile"></a>
<% } %>
</form>
--------------------------
for each record, there is an unique ID value, whenv user click the "edit" image, the parameter "memberIDNumber" will be submited to testID.java
my questions is:
the error i got is: no matter i click which "edit" image of these printed records, the value of "memberIDNumber" i retrived from testID.java is always same
here, i'm using a same valriable name: "memberIDNumber" in the input field. is ithis the reason for the error? it seems it only pased the last element (ID value) in the memberIDList.
Thank you so much for your reply,
lilyyan
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you were actualy submitting one hidden value for each row. In the response servlet you probably retrieved only the first value (getParameterValue).
ASKER
hi enachemc,
thanks so much! this works great : D
only one question, why the response servlet only retrieve the first value?
lilyyan
thanks so much! this works great : D
only one question, why the response servlet only retrieve the first value?
lilyyan
because that is what you request. If you want all the values, request them all: getParameterValues(paramNa me)
ASKER
q1:
getParameterValues(paramNa me) is used for retrieving parameters in an array, so if getParameterValues(paramNa me) in the response servlet, all the value in memberIDList.size() will be retrieved?
========================== =
i once used something like:
while(sqlRst.next()) {
out.println("<tr><td>Core No. </td>");
out.println("<td>File Name</td>");
out.println("<td>Version No.</td>");
.....
out.println("<a href=\"./coreStandardsF/" + fileName+ "\""+ " target=_blank>" +
fileName+ "</a>" +"<form action=\"delteCoreFiles.js p\" method = \"post\" name=\"deleteFilesForm\" onsubmit=\"return disp_confirm(this)\">"+
"<input type=\"hidden\" name=\"filesName\" value=\""+fileName+ "\"/>"+
"<input type=\"submit\" value=\"Delete this file?\" />"+"</form></td><td>");
} // end of while
===================
q2:
in the above code, i used different form for each record, and they all have the same name: "deleteFilesForm"
and the coding is working.
my questions is , why in this case the forms having same name, but it's working?
and in the question of this posting i have to use only one form for all the submit actions?
getParameterValues(paramNa
==========================
i once used something like:
while(sqlRst.next()) {
out.println("<tr><td>Core No. </td>");
out.println("<td>File Name</td>");
out.println("<td>Version No.</td>");
.....
out.println("<a href=\"./coreStandardsF/" + fileName+ "\""+ " target=_blank>" +
fileName+ "</a>" +"<form action=\"delteCoreFiles.js
"<input type=\"hidden\" name=\"filesName\" value=\""+fileName+ "\"/>"+
"<input type=\"submit\" value=\"Delete this file?\" />"+"</form></td><td>");
} // end of while
===================
q2:
in the above code, i used different form for each record, and they all have the same name: "deleteFilesForm"
and the coding is working.
my questions is , why in this case the forms having same name, but it's working?
and in the question of this posting i have to use only one form for all the submit actions?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
will this work?
--------------------------
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<form method="post" action="" name="editForm" >
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get
<a href="#" onClick="submitThisForm(3)
<img src="editable.gif" border="0" alt="Edit profile"></a>
</form>
<% } %>
--------------------------
well, actually it's not working. but i'm not sure the reason.
is that beacuse i'm not uing submit button, instead i'm using a href link to submit the form?
yes and no.
yes .... but
the submitThisForm would have to know what form to submit
yes .... but
the submitThisForm would have to know what form to submit
ASKER
the form name is "editForm", the form id is: editDeleteFormID
is javascript of submitThisForm
document.getElementById("e ditDeleteF ormID").su bmit();
the only difference here is: one is using a submit button and the other is using a href link
but why the one using a href link is not working ?
is javascript of submitThisForm
document.getElementById("e
the only difference here is: one is using a submit button and the other is using a href link
but why the one using a href link is not working ?
ASKER
also in:
-------------------------- ---------- ----
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<form method="post" action="" name="editForm" >
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get (i).toStri ng() %>" />
<a href="#" onClick="submitThisForm(3) ">
<img src="editable.gif" border="0" alt="Edit profile"></a>
</form>
<% } %>
-------------------------- ---------- ------
if i change to:
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<form method="post" action="" name="editForm" >
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get (i).toStri ng() %>" />
< input type="image" src="editable.gif" border="0" alt="Edit profile" value ="Edit">
</form>
<% } %>
-------------------------- ---------- ---------- ---------- --
this is work, right?
--------------------------
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<form method="post" action="" name="editForm" >
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get
<a href="#" onClick="submitThisForm(3)
<img src="editable.gif" border="0" alt="Edit profile"></a>
</form>
<% } %>
--------------------------
if i change to:
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<form method="post" action="" name="editForm" >
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get
< input type="image" src="editable.gif" border="0" alt="Edit profile" value ="Edit">
</form>
<% } %>
--------------------------
this is work, right?
because a submit button is inherently associated with the parent form and will submit the parent form. A function is not part of a form. You will need a way to distinguish the forms.
you can transmit a reference of 'this' to the function from an input of the form to the submitThisForm(3) (like submitThisForm(3, this) ) and in the function, submitThisForm(no, inputEl) use inputEl.form.submit().
ASKER
submitThisForm(3, this) : "this" is referred to the form, right?
inputEl.form.submit(). : inputEl is a variable name which reference to "this",
but why you use another form here: i..e nputEl.form.submit() // .form.
will this work: document.inputEl.submit() ?
also would you please reply my last posting ?
thanks so much
inputEl.form.submit(). : inputEl is a variable name which reference to "this",
but why you use another form here: i..e nputEl.form.submit() // .form.
will this work: document.inputEl.submit() ?
also would you please reply my last posting ?
thanks so much
this is a reference to the input, not the form.
it will not work. There is no one to submit the form.
ASKER
if i change to:
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<form method="post" action="edit.jsp" name="editForm" >
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get (i).toStri ng() %>" />
< input type="image" src="editable.gif" border="0" alt="Edit profile" value ="Edit">
</form>
<% } %>
-------------------------- ---------- ---
the image button is a submit button
<% for (int i=0; i<memberIDList.size(); i++){ %>
code for printing record (i) ....
<form method="post" action="edit.jsp" name="editForm" >
<input type="hidden" name="memberIDNumber" value="<%=memberIDList.get
< input type="image" src="editable.gif" border="0" alt="Edit profile" value ="Edit">
</form>
<% } %>
--------------------------
the image button is a submit button
ASKER
>>this is a reference to the input, not the form.
so in inputEl.form.submit(), inputEl.form is actually reference the input field of the form, right?
i don't know an element of a form can be accessed in this way, may you post some tutorial link about this, if possible?
so in inputEl.form.submit(), inputEl.form is actually reference the input field of the form, right?
i don't know an element of a form can be accessed in this way, may you post some tutorial link about this, if possible?
yes, you're right. And yes, it will work. If this is the entire form, you will have a single parameter named memberIDNumber. Actualy you will also have two parameters named x and y generated by the image input. You can see this in the URL if you change the method of the form from post to get.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so, for example: in the case of submitting a form within a for/while loop and also the submit action is not fired by a real submit button,
i can submit a form through a field reference and plus form, namely the format is :
fieldReference.form // this will reference to the form, is this right?
i can submit a form through a field reference and plus form, namely the format is :
fieldReference.form // this will reference to the form, is this right?
ASKER
i'm not quite get use to this notiation: fieldReference.form,
is there any tutorial link for this?
is there any tutorial link for this?
http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/input_checkbox.asp
You can see that the input has a property of type form
You can see that the input has a property of type form
ASKER
well , i try to find the input has a property of type form from the link : http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/objects/input_checkbox.asp
but i didn't find it, would you please paste the code in that link ?
but i didn't find it, would you please paste the code in that link ?
ASKER
this is code in the link: i didn't see any code indicate that input has a property type of form
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
<INPUT TYPE=checkbox CHECKED ID=chk1 onclick="choosebox1()">Unc heck
this check box for some free advice.
<P><INPUT TYPE=checkbox ID=chk2 onclick="choosebox2()">Or check
this check box for a message from our sponsors.
<P ID=SampText>
This example implements the script when the user clicks either check box.
<SCRIPT>
function choosebox1(){
alert("Never play leapfrog with a unicorn!")
}
function choosebox2(){
SampText.insertAdjacentHTM L("AfterBe gin","Buy WonderWidgets! ");
}
</SCRIPT>
-------------------------- ---------- ---------- ---------- ---------- ---------- -------
--------------------------
<INPUT TYPE=checkbox CHECKED ID=chk1 onclick="choosebox1()">Unc
this check box for some free advice.
<P><INPUT TYPE=checkbox ID=chk2 onclick="choosebox2()">Or check
this check box for a message from our sponsors.
<P ID=SampText>
This example implements the script when the user clicks either check box.
<SCRIPT>
function choosebox1(){
alert("Never play leapfrog with a unicorn!")
}
function choosebox2(){
SampText.insertAdjacentHTM
}
</SCRIPT>
--------------------------
ASKER
really appreciate your replies. these replies are very helpful, sorry if i asked to many questions: D
ASKER
3 A there :D
ASKER
well, this question is actually is an extend of my another question in jsp: "sumbit forms through a javascript and assign each form a different name dynamically".
in that question, the solution is: i used only one form for all submit actions. based on the error in the current posting, i guess i still need to use a different form for each submit action.
or is there another way to solve the error?
thanks so much for your reply,
lilyyan