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).toString() %>" />
<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


lilyyanAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
enachemcConnect With a Mentor Commented:
<form >
<input type="hidden" name="memberIDNumber" id="memberIDNumber" />

<% for (int i=0; i<memberIDList.size(); i++){ %>

code for printing record (i) ....

<a href="#" onClick="document.getElementById('memberIDNumber').value=<%=memberIDList.get(i).toString() %> ;submitThisForm(3)">
    <img src="editable.gif" border="0" alt="Edit profile"></a>

<% } %>

</form>
0
 
lilyyanAuthor Commented:
hello again,

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
0
 
enachemcCommented:
you were actualy submitting one hidden value for each row. In the response servlet you probably retrieved only the first value (getParameterValue).
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
lilyyanAuthor Commented:
hi enachemc,

thanks so much! this works great : D

only one question, why the response servlet only retrieve the first value?

lilyyan
0
 
enachemcCommented:
because that is what you request. If you want all the values, request them all: getParameterValues(paramName)
0
 
lilyyanAuthor Commented:
q1:

getParameterValues(paramName) is used for retrieving parameters in an array, so if getParameterValues(paramName) 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.jsp\"  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?



0
 
enachemcConnect With a Mentor Commented:
yes, it's because of the form(s). Only one form in a webpage is submitted to the server. The other ones are ignored. In your first post, you had one form with more fields with the same name - this would result in more values for a parameter; in your last post here you had multiple forms, each containing one field - this results in sending only the field in the submitted form getting to the server. The others, as I said, are ignored.
0
 
lilyyanAuthor Commented:

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(i).toString() %>" />
<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?

0
 
enachemcCommented:
yes and no.
yes .... but
the submitThisForm would have to know what form to submit
0
 
lilyyanAuthor Commented:
the form name is "editForm", the form id is: editDeleteFormID

is javascript of submitThisForm

document.getElementById("editDeleteFormID").submit();

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 ?
0
 
lilyyanAuthor Commented:
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).toString() %>" />
<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).toString() %>" />
< input type="image" src="editable.gif" border="0" alt="Edit profile" value ="Edit">
</form>
<% } %>

----------------------------------------------------------

this is work, right?

0
 
enachemcCommented:
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.
0
 
enachemcCommented:
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().
0
 
lilyyanAuthor Commented:
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
0
 
enachemcCommented:
this is a reference to the input, not the form.
0
 
enachemcCommented:
it will not work. There is no one to submit the form.
0
 
lilyyanAuthor Commented:
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).toString() %>" />
< input type="image" src="editable.gif" border="0" alt="Edit profile" value ="Edit">
</form>
<% } %>

---------------------------------------

the image button is a submit button
0
 
lilyyanAuthor Commented:
>>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?

0
 
enachemcCommented:
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.
0
 
enachemcConnect With a Mentor Commented:
no, inputEl is a reference to the input (since it comes that way - it is the input that generate the event and calls the function submitThisForm(3, this) ; Here this is the element. then inputEl.form equals the form. Now that you have a reference to the form, you can submit it.
0
 
lilyyanAuthor Commented:
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?
0
 
lilyyanAuthor Commented:
i'm not quite get use to this notiation: fieldReference.form,
is there any tutorial link for this?
0
 
enachemcCommented:
0
 
lilyyanAuthor Commented:
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 ?
0
 
lilyyanAuthor Commented:
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()">Uncheck
    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.insertAdjacentHTML("AfterBegin","Buy WonderWidgets! ");
}
</SCRIPT>

-----------------------------------------------------------------------------------
0
 
lilyyanAuthor Commented:
really appreciate your replies. these replies are very helpful, sorry if i asked to many questions: D
0
 
lilyyanAuthor Commented:
3 A there :D
0
All Courses

From novice to tech pro — start learning today.