开发者

html value of select option to jdo object

I'm doing an query and getting a list of albums names from my JDO, they are then displayed in a selection menu in html like this

  List<NomeAlbum> results = (List<NomeAlbum>) query.execute(utilizador);
    if (!results.isEmpty()) 
    {
        for (NomeAlbum e : results) 
        {
            resultados = resultados + "<option value='"+results.get(i).nome+"'>"+results.get(i).nome+"</option>";

then printed in a selection option made in html

 "</tr><tr><td>Escolha o album<select nam开发者_JS百科e='listaAlbums' id='listaAlbums'>" +
    resultados +
    "</select></td>"+

My problem is that I'm not getting the value of the selected option. For other fields I just do a iterator like this, but this doesn't work in here, i suspect its because it doesnt have any data printed, just a value:

   if (item.getFieldName().equals("titulo")) {
                    byte[] buffer = new byte[8192];
                    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                    int len = stream.read(buffer, 0, buffer.length);
                    outputStream.write(buffer, 0, len);
                    tituloparam = outputStream.toString();

Can someone help me how to save the value of the option selected? Thanks for your time


I didn't get what I was looking for, then I decided to do a workaround. I will try to explain the best I can cause maybe someone may have this doubt in the future.

Trough javascript I changed the value of an textarea whenever the select list it's changed.

<script type="text/javascript">
function album(selectValue,targetTextArea)
{
 var txtNode=document.createTextNode(selectValue);
 var textArea=document.getElementById(targetTextArea);
 textArea.value = selectValue;
}
</script>

Then I just get the value of the textarea like i do for all other textareas like this

  if (item.getFieldName().equals("textarea")) {
                byte[] buffer = new byte[8192];
                ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                int len = stream.read(buffer, 0, buffer.length);
                outputStream.write(buffer, 0, len);
                tituloparam = outputStream.toString();

And there you go, I can get the value for my java class from the html select form. Probably there are better ways, but this was what i could arrange.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜