I have two input fields. First is a field where user writes in any text (ex. product name) and another one is the field called "Alias" of the product name, it is creadet automatically in real time when user writes the product name. it is done with javascript, so my question is how to add some javascript code in order to add some random code like (aSDAS55AD546) AT THE END OF EACH ALIAS.
Here is the code:
the input fields:
product name:
<input id="asd" onKeyUp="keypress()" name="editname_<? echo $languages[$i][0]; ?>[<? echo $key; ?>]" type="text" value="<? echo $item['name'][$languages[$i][0]];?>" />
Alias field:
<input name="editalias[<? echo $key; ?>]" id="sdf" onFocus="javascript:stripspaces(this)" readonly="readonly" type="text" value="<? echo $item['alias'];?>" />
and this is the javascript code:
<script type="text/javascript">
function keypress()
{
var txt=document.getElementById('asd').value;
str1 = " \",'!=:;\йцукенгшщзхъжэдлорпавыфячсмитьбюЙЦУКЕНГШЩЗХЪЭЖДЛОРПАВЫФЯЧСМИТЬБЮăîșțĂÎȘȚ";
str2 = "00000000icukengsszhijedlorpavifacsmitibuICUKENGSSZHIEJDLORPAVIFACSMITIBUaistAIST";
for(i=0; i<str1.length; i++)
{
txt = txt.replace(new RegExp(str1[i],"g"), str2[i]);
}
document.getElementById('sdf').value=txt;
}
</script>
<script type="text/javascript">
$().ready(function(){
$("input#asd").keyup(removeextra).blur(removeextra);
});
function removeextra() {
var initVal = $(this).val();
outputVal = initVal.replace(/[^0-9a-zA-Zа-яА-Я\s'",!ăîșțĂÎȘȚ]/g,"");
if (initVal != outputVal) {
$(this).val(outputVal);
}
};
</script>
This javascript is saving me alot of time. My website is for Russia, and it also translates from russian to english letters.
So please how can i make a random code for alias?
Thanks in advance!