Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

captcha code is showing undefined in ie7?

My captcha code is working fine in all browsers, but it is showing error in ie7.

Here is the fiddle : http://jsfiddle.net/KMupW/4/

Here is my code :

function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))];
    return result;
}
 var code= randomString(5,'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');

 document.getElementById("txtCaptcha").value = code;
 document.getElementById("txtCaptchaDiv").innerHTML = code;  
like image 650
supersaiyan Avatar asked Feb 16 '26 00:02

supersaiyan


1 Answers

result += chars[index];

Problem is here, internet explorer doesn't support string manipulation like arrays, you should write this instead:

result += chars.charAt(index);

So the line should finally be:

result += chars.charAt(Math.round(Math.random() * (chars.length - 1)));

An example: http://jsfiddle.net/XDxR7/2/

like image 58
artahian Avatar answered Feb 18 '26 15:02

artahian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!