如何将隐藏字段值传递给javascript函数 [英] how to pass hidden field value to javascript function

查看:82
本文介绍了如何将隐藏字段值传递给javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我正在使用C#,asp.net,.net framework2.
我正在使用以下javascript

<  脚本    ="  文本/javascript" %> ");

//sum = grid.rows [1] .cells [7] .childNodes [0] .value;

grid.rows [id] .cells [9] .childNodes [0] .value = sum;





}



<  /script  > 

我正在使用隐藏字段

<   asp:HiddenField     ID   ="   runat   服务器"   <%#Eval(" )%> '   / > 



我必须将rowno的值传递给模板列的文本框中的javascript函数.
这个怎么做?


<   asp:TemplateField     HeaderText   ="  span> > 

<   ItemStyle     ="   80px"  BackColor   白色" / > 

<   ItemTemplate  > 

<   asp:TextBox    宽度  ="   ID    txtPL "  runat   服务器" 文本  " )%> '  BorderStyle     BorderColor       OnChange   =" <%#Eval(" )%> )"    AutoPostBack   ="  false" > 

<  /asp:TextBox  > 

<  /ItemTemplate  > 

<   FooterTemplate  > 

<   asp:Label     ID   ="   runat   服务器" / <  /FooterTemplate  > 


<   ControlStyle     ="   80px" / <  /asp:TemplateField  >  

解决方案

使用hiddenfield的clientId属性将客户端ID写入您的JavaScript,然后通过其ID进行查找. /blockquote>

您只需使用

  var  hdvalue =  document  .getElementById('  Hidden1').value 

,这将为您提供javascript内部隐藏字段中的值.


更改

OnChange ="funcsum(<%#Eval(" rowNo)%>)""



OnChange =<%#String.Format("javascript:funcsum(" {0})",Container.DataItemIndex)%>


Hi friends,
I am using C#,asp.net, .net framework2.
I am using the following javascript

<script type="text/javascript">

function funcsum(id)

{


var table = document.getElementById("grdView");




var sum = 0;

var mess=0;

var mess1=0;

mess=table.rows[id].cells[7].getElementsByTagName("input")[0].value;

mess1=table.rows[id].cells[8].getElementsByTagName("input")[0].value;



sum=parseFloat(mess.replace(",","."))+parseFloat(mess1.replace(",","."));







var grid = document.getElementById("<%= grdView.ClientID %>");

//sum = grid.rows[1].cells[7].childNodes[0].value;

grid.rows[id].cells[9].childNodes[0].value = sum;





}



</script>

i am using a hidden field

<asp:HiddenField ID="HFRowNo" runat="server" Value='<%# Eval("rowNo") %>' />



I have to pass the value of rowno to javascript function in the textbox of  template column.
How to do this?


<asp:TemplateField HeaderText="P &amp; L As Per Book">

<ItemStyle Width="80px" BackColor="White"/>

<ItemTemplate>

<asp:TextBox Width="80px" ID="txtPL" runat="server" text='<%# Eval("PL") %>' BorderStyle="None" BorderColor="white" OnChange="funcsum(<%# Eval("rowNo") %>)" AutoPostBack="false" >

</asp:TextBox>

</ItemTemplate>

<FooterTemplate>

<asp:Label ID="lblFPL" runat="server" />

</FooterTemplate>


<ControlStyle Width="80px" />

</asp:TemplateField>

解决方案

Use the clientId property of the hiddenfield to write the client side id to your javascript, then look it up by it''s id.


You simply have to use

var hdvalue = document.getElementById('Hidden1').value

this will give you the value inside the hidden field inside javascript.


Change

OnChange="funcsum(<%# Eval("rowNo") %>)"

to

OnChange=<%# String.Format("javascript:funcsum(''{0}'')",Container.DataItemIndex)%>


这篇关于如何将隐藏字段值传递给javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆