开发者

Undefined error after firefox 4 beta update

Can somebody check my code and tell me where I'm doing wrong. I'm very poor in javascript and using this code from long time, after firefox update from 3.5 to 4 beta, I'm getting undefined error.

function Convert_ONE2TWO()
{
    var arrTWO = new Array( "a", "e", "i");
    var arrONE = new Array( "A", "E", "I");
    str=document.frmConvert.txtONE.value; //input from ONE
    for (i=0;i<3;i++) //Loop for all letters
        {
        strTemp=new RegExp(arrONE[i], "ig");
        开发者_开发问答str=str.replace(strTemp,arrTWO[i]); //Replacing
        }
    document.frmConvert.txtTWO.value=str.toString(); //output to TWO
}

<form name="frmConvert" action="" method="get">
<textarea rows="5" cols="90" name="txtONE"></textarea>
<input name="btnConvertg" value="Create TWO" onclick="Convert_ONE2TWO();" type="Button">
<textarea rows="5" cols="90" name="txtTWO"></textarea>
</form>


Your loop is wrong. You have three array elements, but perform four loop iterations.

Use for (var i = 0; i < 3; i++) and remember that array indices start at 0, not 1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜