...

View Full Version : How to fix this & make compatible with HTML5



Sirag
07-18-2012, 01:50 PM
Hello,

I've got this Persian textbox for my site it's working on most computers but some of them getting this problem when they trying to type two works which is on this keys: [] and replace of utf-8 persian char it appears [ or ] for them but not for me! Other keys are working great!

I thought maybe it needed to be updated or it has some bug need to fix.

Please anyone can help?


function keyEnterToPersian(field, e) {
if ((field.maxLength && field.maxLength != -1 && field.value.length >= field.maxLength) || field.maxLength == 0) {
return;
}
var event = document.all ? window.event : e;
var key = event.keyCode ? event.keyCode : event.which;
if (key > 31) {
if (key < 128) {
var keys = [
0x0020, 0x0021, 0x061B, 0x066B, 0xFDFC, 0x066A, 0x060C, 0x06AF,
0x0029, 0x0028, 0x002A, 0x002B, 0x0648, 0x002D, 0x002E, 0x002F,
0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7,
0x06F8, 0x06F9, 0x003A, 0x06A9, 0x003E, 0x003D, 0x003C, 0x061F,
0x066C, 0x0624, 0x200C, 0x0698, 0x064A, 0x064D, 0x0625, 0x0623,
0x0622, 0x0651, 0x0629, 0x00BB, 0x00AB, 0x0621, 0x0654, 0x005D,
0x005B, 0x0652, 0x064B, 0x0626, 0x064F, 0x064E, 0x0670, 0x064C,
0x0653, 0x0650, 0x0643, 0x062C, 0x005C, 0x0686, 0x00D7, 0x0640,
0x200D, 0x0634, 0x0630, 0x0632, 0x06CC, 0x062B, 0x0628, 0x0644,
0x0627, 0x0647, 0x062A, 0x0646, 0x0645, 0x067E, 0x062F, 0x062E,
0x062D, 0x0636, 0x0642, 0x0633, 0x0641, 0x0639, 0x0631, 0x0635,
0x0637, 0x063A, 0x0638, 0x007D, 0x007C, 0x007B, 0x007E
];
var code = keys[key - 32];
if (event.which) {
pnhMozStringInsert(field, String.fromCharCode(code));
event.preventDefault();
} else {
try {
event.keyCode = code;
} catch(err) {
}
}
}
}
}
function pnhMozStringInsert(elt, newtext) {
var posStart = elt.selectionStart;
var posEnd = elt.selectionEnd;
var scrollTop = elt.scrollTop;
var scrollLeft = elt.scrollLeft;

elt.value = elt.value.slice(0, posStart) + newtext + elt.value.slice(posEnd);
var newpos = posStart + newtext.length;
elt.selectionStart = newpos;
elt.selectionEnd = newpos;
elt.scrollTop = scrollTop;
elt.scrollLeft = scrollLeft;
elt.focus();

}
function switchTextLang(field, event) {
var event = document.all ? window.event : event;
if (event.ctrlKey && event.altKey) {
if (field.lang == "fa") {
field.dir = "ltr";
field.onkeypress = function() {
}
}
else {
field.dir = "rtl";
field.onkeypress = function(event) {
keyEnterToPersian(this, event);
}
}
}
field.lang = field.lang == "fa" ? "en" : "fa";
}

DrDOS
07-18-2012, 02:35 PM
It's written to work in a Mozilla browser, like Firefox.

pnhMozStringInsert

Keleth
07-18-2012, 02:46 PM
Well, no, there's nothing in the phnMozStringInsert function that is strictly limited to Firefox.

I'm assuming you've tried clearing your cache and trying it? Have you noticed any consistencies between computers that work such as OS and browser? The JS console doesn't show anything useful?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum