Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

changing default value in js

Featured Replies

Hi guys,

 

on my site i have script which alters the default encoding (typing) for the users.

 

It shows small box saying EN as default language and if anyone clicks on it, it turns into MK and whatever the user types on the site (forum) it cames up with cyrillic (Macedonian) alphabet.

 

What i want to do is to reverse it, actually to set MK as the default state of the button, and when someone clicks on it to turn into EN.

 

I've tried with changing kirilicaOn == 0 values into 1 and kirilicaOn =1 into 0 but it only changed the aperiance (the text typed by default was latin)

 

here is the code inside the html:

 

<script charset="utf-8" defer="defer"
 src="/kirilica/kirTast.js" type="text/javascript"></script><input id="commentBut" type="button" onclick="onKir(); this.blur(); if (inputField) inputField.focus();" value="EN" style="background-color: #4a5671; color: white; font-weight: bold; border: 1px solid black; font-size: 10px; width: 25px; margin-top: 0px; margin-left:0px;" title="Web keyboard: Click or press [2x Shift] for change" /> (МК - cyrillic, EN - latin)

 

and here is the script itself:

 

//

//

var blnDOM = false, blnIE4 = false; 
if (navigator.userAgent.toLowerCase().indexOf("opera") + 1) blnDOM = true; 
else if (navigator.userAgent.toLowerCase().indexOf("msie") + 1) blnIE4 = true;
else if (document.getElementById) blnDOM = true;
var kirilicaOn = 0;
var shiftK = 0;
var inputField;

document.onkeypress = getKeycode;
document.onkeyup = shiftKey;

addMyLoadEvent(inputs);

function addMyLoadEvent(myfunc)
{
var myoldonload = window.onload;
  if (typeof window.onload != 'function')
  {
	window.onload = myfunc;
  }
  else
  {
	window.onload = function()
	{
		  myoldonload();
		  myfunc();
	}
  }
}	

function onKir()
{
if(kirilicaOn == 0)
{
	kirilicaOn =1;
	document.getElementById("commentBut").value = 'MK';
	document.getElementById("commentBut").style.backgroundColor = 'red';
}
else
{
	kirilicaOn =0;
	document.getElementById("commentBut").value = 'EN';
	document.getElementById("commentBut").style.backgroundColor = '#4a5671';
}
}

function shiftKey(event)
{
if (blnDOM)
{
	if(event.which == 16)
	{
		shiftK++;
		setTimeout("shiftK=0", 300);
		if(shiftK == 2)
		{
			onKir();
			shiftK = 0;				
		}
	}
	else
	{
		shiftK = 0;
	}
}
else if(blnIE4)
{

	if(window.event.keyCode == 16)
	{
		shiftK++;
		setTimeout("shiftK=0", 300);
		if(shiftK == 2)
		{
			onKir();
			shiftK=0;
		}
	}
	else
	{
		shiftK = 0;
	}
}
}


function getKeycode(e)
{	
if (blnIE4 && kirilicaOn == 1 && !event.ctrlKey)
{
	var sRep = cyr5ko_tast(event.keyCode, event.shiftKey);

	if(sRep)
		window.event.keyCode = sRep.charCodeAt();

}
else if (blnDOM && kirilicaOn == 1 && !e.ctrlKey) 
{	
	var charBukva = new String(e.which);
	var blnkey = (e.shiftKey) ? cyr5ko_tast(charBukva, 1) : cyr5ko_tast(charBukva, 0);
	if (blnkey)
	{
		textArea(blnkey);
		return false;
	}
}
}

function install( hElement )
{
if (hElement.addEventListener)
{
	hElement.addEventListener( "focus", function() {inputField = hElement;}, false );
}
else if (hElement.attachEvent)
{
	hElement.attachEvent("onfocus", function() {inputField = hElement;});
}
}


function inputs()
{
var aInputs = document.getElementsByTagName( 'INPUT' );
for( var nI = 0; nI < aInputs.length; nI++ )
{
	if( aInputs[ nI ].type.toLowerCase() == 'text' || aInputs[ nI ].type.toLowerCase() == 'password')
	{
		install( aInputs[ nI ] );
	}
}
var aTextAreas = document.getElementsByTagName( 'TEXTAREA' );
for( var nI = 0; nI < aTextAreas.length; nI++ )
{
	install( aTextAreas[ nI ] );
}
}

var i1 = 0;
var AZBk = new Array();

 AZBk[i1++] = new Array("џ", "Џ", "120", "88");
 AZBk[i1++] = new Array("ќ", "Ќ", "39", "34");
 AZBk[i1++] = new Array("љ", "Љ", "113", "81");
 AZBk[i1++] = new Array("њ", "Њ", "119", "87");
 AZBk[i1++] = new Array("ѕ", "Ѕ", "121", "89");
 AZBk[i1++] = new Array("ж", "Ж", "92", "124");
 AZBk[i1++] = new Array("а", "А", "97", "65");
 AZBk[i1++] = new Array("б", "Б", "98", "66");
 AZBk[i1++] = new Array("в", "В", "118", "86");
 AZBk[i1++] = new Array("г", "Г", "103", "71");
 AZBk[i1++] = new Array("д", "Д", "100", "68");
 AZBk[i1++] = new Array("е", "Е", "101", "69");
 AZBk[i1++] = new Array("з", "З", "122", "90");
 AZBk[i1++] = new Array("и", "И", "105", "73");
 AZBk[i1++] = new Array("ј", "Ј", "106", "74");
 AZBk[i1++] = new Array("к", "К", "107", "75");
 AZBk[i1++] = new Array("л", "Л", "108", "76");
 AZBk[i1++] = new Array("м", "М", "109", "77");
 AZBk[i1++] = new Array("н", "Н", "110", "78");
 AZBk[i1++] = new Array("о", "О", "111", "79");
 AZBk[i1++] = new Array("п", "П", "112", "80");
 AZBk[i1++] = new Array("р", "Р", "114", "82");
 AZBk[i1++] = new Array("с", "С", "115", "83");
 AZBk[i1++] = new Array("т", "Т", "116", "84");
 AZBk[i1++] = new Array("у", "У", "117", "85");
 AZBk[i1++] = new Array("ф", "Ф", "102", "70");
 AZBk[i1++] = new Array("х", "Х", "104", "72");
 AZBk[i1++] = new Array("ц", "Ц", "99", "67");
 AZBk[i1++] = new Array("ч", "Ч", "59", "58");
 AZBk[i1++] = new Array("ш", "Ш", "91", "123");
 AZBk[i1++] = new Array("ѓ", "Ѓ", "93", "125");
 AZBk[i1++] = new Array("ш", "Ш", "353", "352");
 AZBk[i1++] = new Array("џ", "Џ", "273", "272");
 AZBk[i1++] = new Array("ч", "Ч", "269", "268");
 AZBk[i1++] = new Array("ќ", "Ќ", "263", "262");
 AZBk[i1++] = new Array("ж", "Ж", "382", "381");
 AZBk[i1++] = new Array(".", ":", "46", "62");
 AZBk[i1++] = new Array(",", ";", "44", "60");
 AZBk[i1++] = new Array("2", "„", "50", "64");
 AZBk[i1++] = new Array("3", "“", "51", "35");
 AZBk[i1++] = new Array("4", "’", "52", "36");
 AZBk[i1++] = new Array("6", "‘", "54", "94");


function cyr5ko_tast(kod, golemina)
{
	for(var i=0; i<AZBk.length; i++)
	{
		if(golemina)
		{
			toG = AZBk[i][1];
			fromG = AZBk[i][3];
			if (kod == fromG) 
				return toG;
		}
		else
		{
			to = AZBk[i][0];
			from = AZBk[i][2];
			if (kod == from) 
				return to;
		}
	}
	return false;
}

function textArea(intext)
{
var txtarea = inputField;
var text = new String(txtarea.value);
var text1 = text.slice(0,txtarea.selectionStart);
var text3 = text.slice(txtarea.selectionStart, text.length);

txtarea.value = text1 + intext + text3;
txtarea.selectionStart = text1.length+1;
txtarea.selectionEnd = text1.length+1;
}
;

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.