var lat=new Array("q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l",";","'..." />

Смена раскладки клавиатуры на JavaScript

Код JavaScript:

<SCRIPT LANGUAGE="JavaScript">
	var lat=new Array("q","w","e","r","t","y","u","i","o","p","[","]","a","s","d","f","g","h","j","k","l",";","'","z","x","c","v","b","n","m",",",".","/");
	var cyr=new Array("й","ц","у","к","е","н","г","ш","щ","з","х","ъ","ф","ы","в","а","п","р","о","л","д","ж","э","я","ч","с","м","и","т","ь","б","ю",".");

	var latcap=new Array("Q","W","E","R","T","Y","U","I","O","P","{","}","A","S","D","F","G","H","J","K","L",":","'","Z","X","C","V","B","N","M","<",">","?","#","$","^","&",'@');
	var cyrcap=new Array("Й","Ц","У","К","Е","Н","Г","Ш","Щ","З","Х","Ъ","Ф","Ы","В","А","П","Р","О","Л","Д","Ж","Э","Я","Ч","С","М","И","Т","Ь","Б","Ю",",","№",";",":","?",'"');

	function translate1(tex)
	{
		var buf=tex;
		var i;
		for (i=0;i<latcap.length;i++)
			{
			if (tex.charCodeAt(0) < 128)
				buf=replace(buf,latcap[i],cyrcap[i],1,0);
			else
				buf=replace(buf,cyrcap[i],latcap[i],1,0);
			}

		for (i=0;i<lat.length;i++)
			{
			if (tex.charCodeAt(0) < 128)
				buf=replace(buf,lat[i],cyr[i],1,0);
			else
				buf=replace(buf,cyr[i],lat[i],1,0);
			}

		tex=buf;
		return tex;
		}

		function replace(target,oldTerm,newTerm,caseSens,wordOnly) {

			var work = target;
			var ind = 0;
			var next = 0;

			if (!caseSens) {
				oldTerm = oldTerm.toLowerCase();
				work = target.toLowerCase();
			}

			while ((ind = work.indexOf(oldTerm,next)) >= 0) {
				if (wordOnly) {
				var before = ind - 1;
				var after = ind + oldTerm.length;
				if (!(space(work.charAt(before)) && space(work.charAt(after)))) {
					next = ind + oldTerm.length;
					continue;
				}
				}
				target = target.substring(0,ind) + newTerm +
				target.substring(ind+oldTerm.length,target.length);
				work = work.substring(0,ind) + newTerm +
				work.substring(ind+oldTerm.length,work.length);
				next = ind + newTerm.length;
				if (next >= work.length) { break; }
			}

			return target;

		}

</SCRIPT>

Форма:

<FORM METHOD="POST">
			<p><textarea style="width:100%;" name="text2" cols="20" rows="10" wrap="virtual"></textarea></p>
			<p><input type="button" class="btn btn-success" value="Конвертировать" onclick="document.forms[0].text2.value=translate1(document.forms[0].text2.value);">
			<input type="button" class="btn btn-danger" value="Очистить" onclick="document.forms[0].text2.value='';"></p>
		</FORM>

АВТОРИЗАЦИЯ