Asp.net javascript文本框加载值失败 [英] Asp.net javascript Textbox load value failing

查看:64
本文介绍了Asp.net javascript文本框加载值失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我新学习asp.net和javascript。



我有今天工作时的一个问题。我在ajax选项卡容器上有13个测试盒,并且在asp.net下拉列表中有4个项目。这是选择,R1,R2,其他。程序如下。



如果用户选择选择则清除所有13个文本框。



如果用户选择R1那么13个文本框应该加载单个值,如txtprodtion = 50,txtqualty = 10等。



如果用户选择R2那么13个文本box应该加载单独的值,例如txtprodtion = 30,txtqualty = 30等。



我在javascript中使用以下功能但未能在文本框上加载文本。< br $>


asp.net组合框: -



Hello All,

I am newly learning asp.net and javascript.

I have an issue while working today. I am having 13 test boxes on the ajax tab container and have 4 Items in the asp.net drop down. Which are "Select", "R1", "R2", "Other". Procedure is as follows.

If user Selects Select then All 13 text boxes shoule be cleared.

If user selects "R1" Then 13 text boxes should load individaul values such as txtprodtion = 50, txtqualty = 10 etc.

If user selects "R2" Then 13 text boxes should load individaul values such as txtprodtion = 30, txtqualty = 30 etc.

I am uning the following fuction in javascript but failing to load text on text boxes.

asp.net combo box:-

<asp:DropDownList ID="cmbRole" runat="server" Width="200px" onclientclick="javascript:setValues();">   
<asp:ListItem Selected="True" Value="None">-Select-</asp:ListItem>
<asp:ListItem  Value="R1">R1</asp:ListItem>
<asp:ListItem  Value="R2">R2</asp:ListItem>
<asp:ListItem  Value="Other">Other</asp:ListItem>
</asp:DropDownList>





Javascript功能: -





Javascript Function:-

function  setValues() {
//I am trying to use the below three types.
        //  var dop = document.getElementById("cmbRole").value;
        //  var val= document.getElementById('<%=cmbRole.ClientID%>').value;
       //   var val = $('#<%=cmbRole.ClientID%>').value;

        if (val == "R1") {
            var textBox = document.getElementById("txtProduction");
            textBox.value = "50";
        }
        if (val == "R2") {
            var textBox = document.getElementById("txtProduction");
            textBox.value = 30;
        }
    }





请帮忙。提前致谢。



问候。



Kindly help. Thanks in advance.

Regards.

推荐答案

('#<%= cmbRole.ClientID% >')。value;

if (val == R1){
var textBox = document .getElementById( txtProduction);
textBox.value = 50;
}
如果(val == R2){
var textBox = document .getElementById( txtProduction);
textBox.value = 30 ;
}
}
('#<%=cmbRole.ClientID%>').value; if (val == "R1") { var textBox = document.getElementById("txtProduction"); textBox.value = "50"; } if (val == "R2") { var textBox = document.getElementById("txtProduction"); textBox.value = 30; } }





请帮忙。在此先感谢。



问候。



Kindly help. Thanks in advance.

Regards.


亲爱的试试







try this dear



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Testpagejavascript.aspx.cs" Inherits="Examinations_MPBSE_SchoolReg_Excludeforms_Test_pages_Testpagejavascript" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script>
    function  setValues(val) {
//I am trying to use the below three types.
        //  var dop = document.getElementById("cmbRole").value;
        //  var val= document.getElementById('<%=cmbRole.ClientID%>').value;
       //   var val =


('#<%= cmbRole.ClientID%>')。value;

if (val。 value == R1){
var textBox = document.getElementById( txtProduction);
textBox。 value = 50< /跨度>;
}
如果(val。 value == R2){
var textBox = document。 getElementById( txtProduction);
textBox。 value = 30 ;
}
}
< / script >

< / head >
< body >
< 表单 id = < span class =code-keyword> form1
runat = server >
< div >
< asp:DropDownList ID = cmbRole runat = server 宽度 = 200px onclick = javascript:setValues(this); >
< asp:ListItem 已选择 = True = > -Select- < ; / asp:ListItem >
< asp:ListItem = R1 > R1 < / asp:ListItem >
< asp: ListItem Valu e = R2 > R2 < / asp:ListItem >
< asp:ListItem = 其他 > 其他< < span class =code-leadattribute> / asp:ListItem
>
< / asp:DropDownList >
< asp:TextBox ID = txtProduction runat = server > < / asp:TextBox >

< / div >
< / form >
< / body >
< / html >
('#<%=cmbRole.ClientID%>').value; if (val.value == "R1") { var textBox = document.getElementById("txtProduction"); textBox.value = "50"; } if (val.value == "R2") { var textBox = document.getElementById("txtProduction"); textBox.value = 30; } } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="cmbRole" runat="server" Width="200px" onclick="javascript:setValues(this);"> <asp:ListItem Selected="True" Value="None">-Select-</asp:ListItem> <asp:ListItem Value="R1">R1</asp:ListItem> <asp:ListItem Value="R2">R2</asp:ListItem> <asp:ListItem Value="Other">Other</asp:ListItem> </asp:DropDownList> <asp:TextBox ID="txtProduction" runat="server"></asp:TextBox> </div> </form> </body> </html>


这篇关于Asp.net javascript文本框加载值失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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