简体   繁体   English

在第三个文本框中显示两个文本框文本

[英]Show two textbox text into the third

I have three textbox . 我有三个textbox Now what I want is, 现在我想要的是

I want to show the two texbox text with / into the third box. 我想在/的第三个框中显示两个texbox文本。

I tried like this. 我尝试过这样。

function CombineValueText() {
        var txtfirst = document.getElementById('txtSurvey1').value;
        var txtSecond = document.getElementById('txtHissa').value;

        var result = parseInt(txtfirst) / parseInt(txtSecond);
        if (!isNaN(result)) {
            document.getElementById('txt712_1').value = result;
        } else {
            document.getElementById('txt712_1').value = result;
        }
    }

but it is dividing both the values and showing. 但它同时将值和显示相除。

Here is the html 这是HTML

<td class="label">
    Survey No :
</td>
<td class="field">
    <input name="txtSurvey1" type="text" id="Text1" onkeyup="CombineValueText()" onblur="FunDupCheck()"
        style="width: 80%;" />
</td>
<td class="label">
    Hissa No :
</td>
<td class="field">
    <input name="txtHissa" type="text" id="Text2" onkeyup="CombineValueText()" style="width: 80%;" />
</td>
<td class="label">
    7/12 :
</td>
<td class="field">
    <input name="txt712_1" type="text" id="Text3" readonly="readonly" style="width: 30%" />
</td>

When you write this: 当您编写此代码时:

var result = parseInt(txtfirst) / parseInt(txtSecond);

It automatically gets calculated, and you are also checking if the output is !isNaN(result) , which doesn't make any sense. 它会自动进行计算,并且您还要检查输出是否为!isNaN(result) ,这没有任何意义。 I guess you are looking for displaying it as string. 我猜您正在寻找将其显示为字符串。 So get rid of the if condition and make the result to look like a string: 因此,摆脱if条件,并使result看起来像一个字符串:

var result = parseInt(txtfirst) + "/" + parseInt(txtSecond);

And you should just have: 而且您应该只有:

document.getElementById('txt712_1').value = result;

Also, you don't need the parseInt , which is used only for calculation. 另外,您不需要parseInt ,后者仅用于计算。 Technically you are combining the two strings with a / : 从技术上讲,您将两个字符串用/组合在一起:

var result = txtfirst + "/" + txtSecond;

One more thing is, you need to use the id values for getElementById , so change it to: 还有一件事,您需要将id值用于getElementById ,因此将其更改为:

var txtfirst = document.getElementById('Text1').value;
var txtSecond = document.getElementById('Text2').value;
document.getElementById('Text3').value = result;

Final Code 最终密码

 function CombineValueText() { var txtfirst = document.getElementById('Text1').value; var txtSecond = document.getElementById('Text2').value; var result = txtfirst + "/" + txtSecond; document.getElementById('Text3').value = result; } function FunDupCheck() { } 
 <table> <tr> <td class="label"> Survey No : </td> <td class="field"> <input name="txtSurvey1" type="text" id="Text1" onkeyup="CombineValueText()" onblur="FunDupCheck()" style="width: 80%;" /> </td> <td class="label"> Hissa No : </td> <td class="field"> <input name="txtHissa" type="text" id="Text2" onkeyup="CombineValueText()" style="width: 80%;" /> </td> <td class="label"> 7/12 : </td> <td class="field"> <input name="txt712_1" type="text" id="Text3" readonly="readonly" style="width: 30%" /> </td> </tr> </table> 

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

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