简体   繁体   English

将javascript变量值转换为html:隐藏值

[英]javascript variable value into html:hidden value

i'm adding dynamically struts taglib html:hidden field into javascript code. 我将动态struts taglib html:hidden字段添加到javascript代码中。 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 ie"+selectedValue+". 即使prezziSize和selectedValue都正确设置了值,我也不能将selectedValue值插入隐藏字段中,而只能使用其名称,即“ + selectedValue +”。 On the other hand the list index prezziSize is correctly written in the rendered page. 另一方面,列表索引prezziSize被正确地写入了呈现的页面中。

What am i messing with? 我在搞什么?

thanks bye 谢谢再见

Assuming combo is a select element 假设组合是一个选择元素

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

Have you tried getting selectedValue by doing 您是否尝试过通过获取selectedValue

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+'" 您缺少'包装值='+ selectedvalue +'-应该为value =“'+ selectedValue +'”

  var row='<html:hidden property="listaPrezzoForm['+combo+'].idUAServizio" value="'+selectedValue+'"/>';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM