Question

i'm adding dynamically struts taglib html:hidden field into javascript code. So i have:

<script type="text/javascript">
function addRow(index){
  var prezziSize = parseInt($('#prezziSize').val());
  var selectedValue = combo.options[combo.selectedIndex].innerHTML;
  ...
  var row='<html:hidden property="listaPrezzoForm['+prezziSize+'].idUAServizio" value="+selectedValue+"/>';
  ...
 $(row).appendTo(div); 
}

Even if both prezziSize and selectedValue are correctly valued, i cannot insert into the hidden field the selectedValue value, but just it's name i.e."+selectedValue+". On the other hand the list index prezziSize is correctly written in the rendered page.

What am i messing with?

thanks bye

Was it helpful?

Solution

Assuming combo is a select element

var combo = document.getElementById("combo");

Have you tried getting selectedValue by doing

var selectedValue = combo.options[combo.selectedIndex].value;

or

var selectedValue = combo.options[combo.selectedIndex].text;

Edit - unless that's fine and I misunderstood the question, this line may be incorrect, as well; you were missing 's wrapping value="+selectedvalue+" - should be value="'+selectedValue+'"

  var row='<html:hidden property="listaPrezzoForm['+combo+'].idUAServizio" value="'+selectedValue+'"/>';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top