1

i was rounding off the value to .25,.50,.75 and .00 in the javascript. and the code is as below.

function roundOff(obj) {
    //alert(document.getElementById("sample").value);
    var val=obj.value;
    var newValue;

    var floorValue = Math.floor(val);
    var remainder = val - floorValue;
    if (remainder < 0.325) {
        if (remainder < 0.125) {
            newValue = floorValue;

        } else {
            newValue = floorValue + 0.25;
        }
    } else {
        if (remainder < 0.625) {
            newValue = floorValue + 0.5;
        } else if (remainder < 0.875) {
            newValue = floorValue + 0.75;
        } else {
            newValue = floorValue + 1;
        }
    }
    alert(floorValue);

        alert(newValue);
        document.getElementById("sample").value=newValue;

    //return obj;
}

but am not able to put the value back to the jsp page. if i type 5.5, only 5 is displayed in the jsp. but if i put alert and check the value of floorvalue then it is 5.5. but if i put it to the textbox in jsp it is giving only 5. why is it so???

4

4 回答 4

0

尝试使用 onblur 事件。因为它在小提琴中工作正常。除此之外,我认为您的代码没有问题。

于 2012-07-24T11:57:21.333 回答
0

我在导致麻烦的jsp中使用onKeyUp。相反,我将其更改为 onBlur,因为它提供了与我的要求相同的效果。并感谢您的建议。它现在工作。

于 2012-07-24T04:41:37.807 回答
0

您将文本框的值设置为 floorValue,而不是 newValue。

于 2012-07-23T06:20:48.373 回答
-1

你可以这样试试

document.getElementById("sample").value="+floorValue+";

如果可行,您可以在此处参考原因第四个问题

于 2012-07-23T06:13:36.577 回答