开发者

Undefined error after firefox 4 beta update

开发者 https://www.devze.com 2023-02-16 18:27 出处:网络
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.

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

精彩评论

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

关注公众号