File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Setting a hidden feild Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Setting a hidden feild" Watch "Setting a hidden feild" New topic
Author

Setting a hidden feild

aakil
Greenhorn

Joined: Sep 30, 2003
Posts: 13
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

Joined: Sep 30, 2003
Posts: 13
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Sep 30, 2003
Posts: 13
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

Joined: Sep 30, 2003
Posts: 13
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting a hidden feild
 
Similar Threads
onchange and form.submit() does not work
javascript function returning undefined
trying to submit form on another site from my JSP
How to get pair values using getParameterNames?
Problems with Indexed Properties, Hidden Values and Logic Iterate Tag