Click here to Skip to main content
15,892,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:-

JavaScript
<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 Function:-

JavaScript
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.
Posted
Comments
VICK 3-Jul-13 2:55am    
Do you just want to sort this out through JavaScript??

Why dont you use Server Side code..i.e on basis of Dropdownlist index change you can perform what you want.

1 solution

try this dear



XML
<%@ 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";
        }
        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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900