How to pass a Dynamic String value into a Form..?
Hi all...,
I'm trying to use a JSP to search "audios" stored in a "Audios" table & display the result list in another JSP. (This task was successful).
Now I want to "Rate" these by taking the "Audio Name" as the key. My coding looks as follows...
List myList = (List)request.getAttribute("SongList");
Iterator itr = myList.iterator();
{
while(itr.hasNext())
{
String mySongName = (String)itr.next();
out.println("<form name="SongRatingForm" action="ControllerServlet.java" method="post" >");
out.println("<input type="What is the type here? (is there something like a LABEL)" name="MySongList" value="How can Iinsert 'mySongName' here">");
out.println("</form>");
}
}
Thanks in advance..,
- Asela -
# 1
Hi, please use the 'code' tags; select the text and click the code button when you're posting, it makes things easier to read.
> out.println("<input type="What is the type here? (is
> there something like a LABEL)" name="MySongList"
> value="How can Iinsert 'mySongName' here">");
>
Where do you want to print this? If it is to appear in a text-box, then the input type should be "text". If it is a button ( really? ) it should be "button" or "submit" or "reset".
If you just want the text to print, then you don't need to create and <input/> tag. Just print it out like
<%=mySongName%>
It could be the contents of a <td> of a <table>
Or you could use a <label> tag:
<label> <%=mySongName%></label>
# 2
Hi nogoodatcoding ...
Thanx for the advice & one more question...
Let's say that we printed the "mySongName" on a label...
Now I need to take this "mySongName" as a KEY value for RATING.
(For RATING there's 5 RadioButtons & 1 SubmitButton, lies in a FORM).
Will I be able to pass the "mySongName" into the FORM as a KEY..?
(No ryt..? Coz <label> does not have an attribute called name..).
Appreciate ur help...,
Thanx again,
- Asela -
# 3
out.println("<form name="SongRatingForm" action="ControllerServlet.java" method="post" >");
List myList = (List) request.getAttribute("SongList");
Iterator itr = myList.iterator();
{
while(itr.hasNext())
{
String mySongValue = (String)itr.next();
out.println("<input type="text" name="mySongName" value="+ mySongValue +" />");
}
}
out.println("<input type="submit" name="MySongSubmit" value="Submit song name" />");
out.println("</form>");
# 4
> Will I be able to pass the "mySongName" into
> the FORM as a KEY..?
I didn't quite get what you want to do. What exactly do you mean 'pass to the form'? And do you want to achieve this with JavaScript or in JSP?
Labels are just that; labels. You are right, they do not have a 'name' attribute and they are not submitted with the form so will not be available with getParameter().
If you could give a few more details, then maybe I'll get a better picture of what you want to achieve and where you're having a problem.