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;
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With