Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

how to get the parameter values, should  the parameter names is assigned danamically ?

Posted on 2006-11-29
28
Medium Priority
?
242 Views
Last Modified: 2010-04-01
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


0
Comment
Question by:lilyyan
  • 15
  • 13
28 Comments
 

Author Comment

by:lilyyan
ID: 18038370
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
 
LVL 12

Accepted Solution

by:
enachemc earned 1600 total points
ID: 18038617
<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
 
LVL 12

Expert Comment

by:enachemc
ID: 18038626
you were actualy submitting one hidden value for each row. In the response servlet you probably retrieved only the first value (getParameterValue).
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:lilyyan
ID: 18039391
hi enachemc,

thanks so much! this works great : D

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

lilyyan
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18039576
because that is what you request. If you want all the values, request them all: getParameterValues(paramName)
0
 

Author Comment

by:lilyyan
ID: 18039746
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
 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 1600 total points
ID: 18039802
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
 

Author Comment

by:lilyyan
ID: 18039973

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
 
LVL 12

Expert Comment

by:enachemc
ID: 18040022
yes and no.
yes .... but
the submitThisForm would have to know what form to submit
0
 

Author Comment

by:lilyyan
ID: 18040248
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
 

Author Comment

by:lilyyan
ID: 18040301
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
 
LVL 12

Expert Comment

by:enachemc
ID: 18040304
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
 
LVL 12

Expert Comment

by:enachemc
ID: 18040352
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
 

Author Comment

by:lilyyan
ID: 18040427
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
 
LVL 12

Expert Comment

by:enachemc
ID: 18040447
this is a reference to the input, not the form.
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18040456
it will not work. There is no one to submit the form.
0
 

Author Comment

by:lilyyan
ID: 18040528
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
 

Author Comment

by:lilyyan
ID: 18040558
>>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
 
LVL 12

Expert Comment

by:enachemc
ID: 18040571
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
 
LVL 12

Assisted Solution

by:enachemc
enachemc earned 1600 total points
ID: 18040585
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
 

Author Comment

by:lilyyan
ID: 18040717
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
 

Author Comment

by:lilyyan
ID: 18040729
i'm not quite get use to this notiation: fieldReference.form,
is there any tutorial link for this?
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18040760
0
 

Author Comment

by:lilyyan
ID: 18040923
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
 

Author Comment

by:lilyyan
ID: 18041007
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
 

Author Comment

by:lilyyan
ID: 18041141
really appreciate your replies. these replies are very helpful, sorry if i asked to many questions: D
0
 

Author Comment

by:lilyyan
ID: 18041189
3 A there :D
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
The decision to migrate to the cloud is not a simple one—many factors, such a cost, ease of use, and ongoing maintenance come into play. The goal is always for cloud platforms to make storage and backups more seamless and effective. Here’s a look at…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question