Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting a hidden feild

 
aakil
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
form element
-----------------
<form method="post" name="fillListForm" >
<input type="hidden" name="selectedJobs" value="">
</form>
script to assign the hidden feild
-----------------------------------
for (i=1, i< noOfJobs; i++) {
document.fillListForm.selectedJobs.value =
fillListForm.selectItem.options[i].text + "*" +
fillListForm.selectItem.options[i].value;
}
retrieving the value at receiving page
-----------------------------------------
<%
String[] selectedJobs = request.getParameterValues("selectedJobs");
System.out.println("selectedJobs length "+ selectedJobs.length);
if (selectedJobs != null) {
for (int i = 0; i < selectedJobs.length; i++) {
System.out.println("selectedJobs "+ i +" :"+selectedJobs );
}
}
%>
the result is (even though there are say five items in selectedJobs)
selectedJobs length 1
selectedJobs 0 :[Ljava.lang.String;@d1e7c2
But....
If I manually set the hidden feild like this
<form action="indexedParameters.jsp" method="POST">
<input type="hidden" name="indexed" value="1">
<input type="hidden" name="indexed" value="2">
<input type="hidden" name="indexed" value="3">
</form>
this gives me correct values, what am I missing
Please Help
 
aakil
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stupid Me
System.out.println("selectedJobs "+ i +" :"+selectedJobs );
not including selectedJobs[i] in the loop was the reason for
selectedJobs 0 :[Ljava.lang.String;@d1e7c2
I noticed two things now
1) The selected length is always one and contains the last entry
2) document.fillListForm.selectedJobs.value[i] did not throw any script error
altho it did not give any useful results
Anybody pls tell me how to assign multiple values to a hidden item from a loop using script
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for (i=1, i< noOfJobs; i++) {
document.fillListForm.selectedJobs.value =
fillListForm.selectItem.options[i].text + "*" +
fillListForm.selectItem.options[i].value;
}
that is just overwriting the information EVERY time you loop
You are saving the information into the same spot.....
You are not going to get the effect you want by using += instead of =
 
aakil
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Eric
Well I guess I am not making myself clear here. I am not planning to append to the existing string using " += ", but I am trying to make a array like feild for "selectedJobs" variable, so that I can get the values at the receiving end using "request.getParameterValues('selectedJobs')" as an array. This is what happens when you try to do this
<form action="indexedParameters.jsp" method="POST">
<input type="hidden" name="indexed" value="1">
<input type="hidden" name="indexed" value="2">
<input type="hidden" name="indexed" value="3">
</form>
here the value of feild "indexed" does not get overwritten, but it becomes an index so that getParameterValues() will get it as an array in JSP.
I want to replace the functionality of the above three <input> tag lines from a script method
Any thoughts on these lines
 
aakil
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am trying to pass an array of strings between pages can somebody pls explain how to set values to an array thru a javascript method.
This is what I had done so far
//this is "abc.jsp"
<head>
<script language="JavaScript">
function trys() {
//this javascript loop is throwing an error, saying
// "document.see.sels is null or not an object" I am trying it with IE6
for (i=0; i<5; i++) {
document.see.sels[i].value = "changed "+i;
}
window.see.action="bcd.jsp";
window.see.submit();
}
</script>
</head>
<body>
<form name="see" action="" method="post">
<input type="button" name="but" value="look" onKlick="trys()">
//onclick is renamed as onKlick due to javaranch requirements
<input type="hidden" name="sels[]">
</form>
</body>

//this is "bcd.jsp"
<%
String[] ans = request.getParameterValues("sels");
if (ans != null) {
for (int i=0; i<ans.length; i++) {
System.out.println("sels:"+ ans[i]);
}
}
%>
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay,
I am trying to figure out what you are trying to do with this information. I might have an easier way for you to handle this.
You are taking multiple selections from a drop down right? This is where I am lost. On the jsp, you should be able to get all of the values and text straight from that. That is why I am lost that you are trying to get the values into hidden elements.
Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic