Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/463.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 选中框时填充框,如何处理?_C#_Javascript_Asp.net_Vb.net - Fatal编程技术网

C# 选中框时填充框,如何处理?

C# 选中框时填充框,如何处理?,c#,javascript,asp.net,vb.net,C#,Javascript,Asp.net,Vb.net,我以前问过这个问题,但没有得到任何帮助 我将试着重新措辞一下 我有5个输入框;让我们称它们为chck1、chck2、chck3、chck4和chck5 每个输入框都有一个关联的复选框,让我们称它们为chckbox1、chckbox2、chckbox3、chckbox4、chckbox5。这些都在一个名为“***步骤3*** 规范是,如果您在其中一个输入框中输入一个数字,并在步骤3中选中关联的复选框,则该数字将在步骤4中填充到相应的框中 例如,如果我选中一个名为chckbox1的复选框,并在步骤3

我以前问过这个问题,但没有得到任何帮助

我将试着重新措辞一下

我有5个输入框;让我们称它们为chck1、chck2、chck3、chck4和chck5

每个输入框都有一个关联的复选框,让我们称它们为chckbox1、chckbox2、chckbox3、chckbox4、chckbox5。这些都在一个名为“***步骤3***

规范是,如果您在其中一个输入框中输入一个数字,并在步骤3中选中关联的复选框,则该数字将在步骤4中填充到相应的框中

例如,如果我选中一个名为chckbox1的复选框,并在步骤3中的chck1中输入一个数字,则只要选中步骤3中输入框旁边的复选框,该数字就会在步骤4中填充到CHCKU amt中

如果在步骤3中的任何框中输入了一个数字,但未选中关联的复选框,则在步骤4中,该数字不会填充到相应的框中

到目前为止,我遇到的问题是,如果我在输入数字之前先选中一个框,那么步骤4中相应的框就会被填充

但是,如果在选中相关复选框之前,我在步骤3的框中输入了一个数字,则该数字不会填充到步骤4的相应框中

是否有人知道如何确保在步骤3中先输入一个数字,还是先选中一个框,只要选中一个框,该数字就需要在步骤4中填充到相应的框中

有人能帮忙吗

我知道这很复杂,但我相信这里的大师可以提供帮助

这是步骤3和步骤4的标记

提前多谢

        '**********Step 3******************* 
    <asp:TableCell><asp:TextBox ID="chck1" runat="server" Width="75px" Text = "0" onchange="caltot('tot_amt1','chck1','onetime1','multi1')" AutoPostBack = "True" Ontextchanged = "getAmt"></asp:TextBox> 
    <asp:CheckBox ID="chckBox1" runat="server"  AutoPostBack = "True" /></asp:TableCell> 
    <asp:TableCell><asp:TextBox ID="chck2" runat="server" Width="75px" Text = "0" onchange="caltot('tot_amt2','chck2','onetime2','multi2')" AutoPostBack = "True" Ontextchanged = "getAmt"></asp:TextBox> 
    <asp:CheckBox ID="chckBox2" runat="server"  AutoPostBack = "True" /></asp:TableCell> 
    <asp:TableCell><asp:TextBox ID="chck3" runat="server" Width="75px" Text = "0" onchange="caltot('tot_amt3','chck3','onetime3','multi3')" AutoPostBack = "True" Ontextchanged = "getAmt"></asp:TextBox> 
    <asp:CheckBox ID="chckBox3" runat="server"  AutoPostBack = "True" /></asp:TableCell> 
    <asp:TableCell><asp:TextBox ID="chck4" runat="server" Width="75px" Text = "0" onchange="caltot('tot_amt4','chck4','onetime4','multi4')" AutoPostBack = "True" Ontextchanged = "getAmt"></asp:TextBox> 
    <asp:CheckBox ID="chckBox4" runat="server"  AutoPostBack = "True" /></asp:TableCell> 
    <asp:TableCell><asp:TextBox ID="chck5" runat="server" Width="75px" Text = "0" onchange="caltot('tot_amt5','chck5','onetime5','multi5')" AutoPostBack = "True" Ontextchanged = "getAmt"></asp:TextBox> 
    <asp:CheckBox ID="chckBox5" runat="server"  AutoPostBack = "True" /></asp:TableCell> 

                        | 
                        V 

 '**********Step 4******************* 
 <asp:TableCell><asp:TextBox ID="chck1_amt" runat="server" Width="90px" Text = "0"></asp:TextBox></asp:TableCell> 
 <asp:TableCell><asp:TextBox ID="chck2_amt" runat="server" Width="90px" Text = "0"></asp:TextBox></asp:TableCell> 
 <asp:TableCell><asp:TextBox ID="chck3_amt" runat="server" Width="90px" Text = "0"></asp:TextBox></asp:TableCell> 
 <asp:TableCell><asp:TextBox ID="chck4_amt" runat="server" Width="90px" Text = "0"></asp:TextBox></asp:TableCell> 
 <asp:TableCell><asp:TextBox ID="chck5_amt" runat="server" Width="90px" Text = "0"></asp:TextBox></asp:TableCell> 


  If chckamttext.Text <> "0" Then
            Select Case chckded
                Case "chck1"
                    If chckBox1.Checked Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname1.Text
                    End If
                Case "chck2"
                    If chckBox2.Checked Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname2.Text
                    End If

                Case "chck3"
                    If chckBox3.Checked Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname3.Text
                    End If

                Case "chck4"
                    If chckBox4.Checked Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname4.Text
                    End If

                Case "chck5"
                    If chckBox5.Checked Then
                        chckamtbot.Text = chckamttext.Text
                        chckfed.Text = fedname5.Text
                    End If
            End Select
        ElseIf chckamttext.Text = "0" And chckded <> "" Then
            chckamtbot.Text = "0"
            chckfed.Text = ""
        End If
        chckamttot.Text = CDec(chck1_amt.Text) + CDec(chck2_amt.Text) + CDec(chck3_amt.Text) + CDec(chck4_amt.Text) + CDec(chck5_amt.Text)
”**********步骤3*********************************
| 
v
“**********第4步***************************
如果chckamttext.Text为“0”,则
选择案例chckded
案例“chck1”
如果chckBox1.已选中,则
chckamtbot.Text=chckamttext.Text
chckfed.Text=fedname1.Text
如果结束
案例“chck2”
如果chckBox2.已选中,则
chckamtbot.Text=chckamttext.Text
chckfed.Text=fedname2.Text
如果结束
案例“chck3”
如果chckBox3.已选中,则
chckamtbot.Text=chckamttext.Text
chckfed.Text=fedname3.Text
如果结束
案例“chck4”
如果chckBox4.已选中,则
chckamtbot.Text=chckamttext.Text
chckfed.Text=fedname4.Text
如果结束
案例“chck5”
如果chckBox5.已选中,则
chckamtbot.Text=chckamttext.Text
chckfed.Text=fedname5.Text
如果结束
结束选择
ElseIf chckamttext.Text=“0”和chckded”然后
chckamtbot.Text=“0”
chckfed.Text=“”
如果结束
chckamttot.Text=CDec(chck1金额文本)+CDec(chck2金额文本)+CDec(chck3金额文本)+CDec(chck4金额文本)+CDec(chck5金额文本)

我希望这样的东西对你有用

    <form>
<input type="checkbox" ID="chckBox1" name="checkbox1" value="1" onchange="onChange('chckBox','chck','1');" /> chck1 <input id="chck1" type="text" name="chck1" onkeyup="onChange('chckBox','chck','1');"/><br />

<input type="checkbox" ID="chckBox2" name="checkbox2" value="2" onchange="onChange('chckBox','chck','2');"/> chck2 <input id="chck2" type="text" name="chck2" onkeyup="onChange('chckBox','chck','2');"/><br />

<input type="checkbox" ID="chckBox3" name="checkbox3" value="3" onchange="onChange('chckBox','chck','3');"/> chck3 <input id="chck3" type="text" name="chck3" onkeyup="onChange('chckBox','chck','3');"/><br />

<input type="checkbox" ID="chckBox4" name="checkbox4" value="4" onchange="onChange('chckBox','chck','4');"/> chck4 <input id="chck4" type="text" name="chck4" onkeyup="onChange('chckBox','chck','4');"/><br />

<input type="checkbox" ID="chckBox5" name="checkbox5" value="5" onchange="onChange('chckBox','chck','5');"/> chck5 <input id="chck5" type="text" name="chck5"onkeyup="onChange('chckBox','chck','5'); "/><br /><br/>
<br /><br/>



1<input id="chck1_amt" type="text" name="chck1_amt" /><br />
2<input id="chck2_amt"type="text" name="chck2_amt" /><br />
3<input id="chck3_amt"type="text" name="chck3_amt" /><br />
4<input id="chck4_amt"type="text" name="chck4_amt" /><br />
5<input id="chck5_amt" type="text" name="chck5_amt" /><br />


</form>

<script  type="text/javascript">

function onChange(boxID, textID, theNumber){

    //see if box box id is checked 
    var checkStatus = document.getElementById(boxID+theNumber);

    if (checkStatus.checked == true){
        //get value of the textbox id
        var textValue = document.getElementById(textID+theNumber).value;
        //alert(textNumber)
        updateBox(theNumber,textValue);
    }
    //not checked so updating with nothing
    else {
        updateBox(theNumber,'');
    }
}


function updateBox(theNumber,textNumber){
    var updateBox = document.getElementById('chck'+theNumber+'_amt');
    if(updateBox){
        updateBox.value = textNumber;
        console.log('updating: '+theNumber+'  -'+updateBox)
    }
}


</script>

chck1
chck2
chck3
chck4
chck5



1
2
3
4
5
函数onChange(boxID、textID、编号){ //查看是否选中了框id var checkStatus=document.getElementById(boxID+编号); if(checkStatus.checked==true){ //获取文本框id的值 var textValue=document.getElementById(textID+theNumber).value; //警报(文本编号) updateBox(编号、文本值); } //未选中,因此更新时没有任何内容 否则{ updateBox(编号为“”); } } 函数更新框(编号、文本编号){ var updateBox=document.getElementById('chck'+theNumber+'u amt'); if(updateBox){ updateBox.value=textNumber; log('更新:'+theNumber+'-'+updateBox) } }
如果复选框被选中且相应的文本框不为空,则不执行任何操作,否则用值填充框,您不能在代码中处理此问题吗?大概是这样的:

if(chckBox1.Checked && chck1.Text.Trim() != String.Empty)
{
//Populate appropriate box
}

非常非常感谢您的快速回复用户918850,我注意到您的输入框与我发布的输入框不同。Mine使用asp.net控件。这有关系吗?你的js还会和我的asp.net控件一起工作吗?我不确定。。。如果您的输入框ID相同,我不明白为什么不一样。试试看。或者试着用代码处理相同的概念。1.单击复选框或更新文本框时,请选中复选框以查看复选框值。2.如果复选框==单击,则更新相应的文本框。如果未单击复选框,则删除相应的文本框。它们不相同。它们是chck1到chck5。我更关心的是,我的控件已经在使用onchange事件处理程序。也许,如果你能向我展示如何将我当前的onchange事件与你的合并,我想我能做到。请参阅我的原始帖子,了解step3代码。这件事不允许我为您的方便再次发布代码。在我看来,您将复选框命名为chckBoxN(chckbox1)、文本框命名为chckN(chck1)和结果命名为chckN_amt(chck1_amt)。我的代码完全一样。您的复选框onclick或onchange将需要变成“onchange('chckBox','chck','1');“您的文本框在keypress或keyup上需要变成“onchange('chckBox','chck','1');”,并且用复选框的编号替换1。chckBox参数用于查找checkbox元素。第二个参数“chck”用于查找文本框值i和j