-2

私はユニ科目の割り当てを行っており、javascript に問題があります。別のフィールドの値に基づいて入力フィールドの値を変更できるようにしたいと考えています。つまり、1 つのフィールドに製品の数量を入力し、その隣のフィールドを変更して、その数量の製品を購入するために必要な合計金額を表示することを目的としています。

HTML を実行すると、入力した数量によってコスト フィールドの値が変更されず、javascript に何か問題があるに違いないと考えています。

これは私のjavascript関数のコピーと、それを実行するための関連するhtmlです。

脚本:

function calcRowWash(){ 
    var theForm = document.forms["orderform"];
    var x = theForm.getElementById("quantc").value;
    var quantity = 0;
    if(x.value!=""){
        quantity = parseInt(x.value);
    }
    var totalC = (quantity*0.30);
    document.getElementById("totc").value = totalC;
    return;
}

HTML:

<td width = "90px" align ="left"><input type = "text" id ="quantc" name = "quantWash" size = "5" tabindex = "13" onblur="calcRowWash()"/></td>
<td width = "90px" align ="left"><input type = "hidden" id ="totc" name = "washtotal" size = "5" tabindex = "14" value=""/></td>    

助けてくれてありがとう!。

4

6 に答える 6

0

このコードで試してください

    function calcRowWash() {
        var x = document.forms[0]['quantc'].value;
        var quantity = 0;
        if (x != "") {
            quantity = parseInt(x);
        }
        var totalC = (quantity * 0.30);
        document.forms[0]['totc'].value = totalC.toString();

    }

HTMLマークアップ、テキストボックスの隠しタイプを変更しましたが、うまくいきます。

   <td width = "90px" align ="left"><input type = "text" id ="quantc" tabindex = "13" onblur="calcRowWash()"/></td>
 <td width = "90px" align ="left"><input type = "text" id ="totc" tabindex = "13"/></td>  </div>
于 2012-05-27T16:56:52.517 に答える
0
var theForm = document.forms["orderform"]; 
var x = theForm.getElementById("quantc").value; 

これは冗長です。ID はドキュメント全体で一意であるため、これで十分です。

var x = document.getElementById('quantc');

また、削除したことにも注意してください.value-これは問題でした。これは、値を取得しようとしたためです...値の。

于 2012-05-27T16:16:46.770 に答える
0

これは機能します。

calcRowWash = (function(){
    var x = document.getElementById("quantc");
    var quantity = 0;

    if (x.value!="") quantity = parseInt(x.value);

    var totalC = (quantity*0.30);
    document.getElementById("totc").value = totalC;

});

JSFiddle

于 2012-05-27T16:24:17.340 に答える
0
function calcRowWash(){ 
    var theForm = document.forms["orderform"];
    var x = theForm.getElementById("quantc").value;
    var quantity = 0;

    // Check if it is not empty
    if(x.value != ""){
        // Check if it is a valid number
        if(x / x == 1){
            quantity = parseInt(x.value);
        }
    }
    var totalC = (quantity * 0.30);
    document.getElementById("totc").value = totalC;
}

これは私にとってはうまくいきます。

于 2015-04-04T19:31:30.440 に答える
-1
<form name="myForm" action="#" method="POST">
   <input type = "text" id="quantc" name = "quantWash" size = "5" tabindex = "13"   onblur="calcRowWash()"/>
   <input type = "hidden" id ="totc" name = "washtotal" size = "5" tabindex = "14" value=""/>
</form>

function calcRowWash(){ 
   var quantity = document.myForm.quantWash.value; 
   var price = 10.0;
   document.myForm.washtotal.value = quantity * price;
}

この関数には、解析機能は含まれていません。両方の入力フィールドの値を読み取って設定する方法を示したいだけです。

于 2012-05-27T16:21:00.793 に答える
-2

このJavaScriptコードを使用できます。

var inp = document.getElementById("inp"); // getting the Input ID
function change_value() {
    inp.value = 'Your Value'; // <-- value 
}

イベントを追加できます。

inp.onfocus = change_value;
inp.onblur = another function with another action;

幸運のリアムと良い一日を。

于 2012-05-27T16:17:30.550 に答える