I am trying to implement my script into Wordpress but for some reasons it just doesn't simply work. And whenever I try to test it online, it doesn't work either... Only when I'm offline does it work.
Here is the script :
<script type="text/javascript">
function copyit(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
therange=tempval.createTextRange()
therange.execCommand("Copy")
}
function results()
{
var behavior="form";
var text=document.csrAlpha.csrresult2.value;
var uccvt=text.toLowerCase();
var Words=new Array;
Words["a"]="Alpha";
Words["b"]
="Bravo";
Words["c"]="Charlie";
Words["d"]="Delta";
Words["e"]="Echo";
Words
["f"]="Foxtrot";
Words["g"]="Golf";
Words["h"]="Hotel";
Words["i"]="India";
Words["j"]="Juliet";
Words["k"]="Kilo";
Words["l"]="Lima";
Words["m"]="Mike";
Words["n"]="November";
Words["o"]="Oscar";
Words["p"]="Papa";
Words["q"]="Quebec";
Words["r"]="Romeo";
Words["s"]="Sierra";
Words["t"]="Tango";
Words["u"]="Uniform";
Words["v"]="Victor";
Words["w"]="Whiskey";
Words["x"]="X-Ray";
Words["y"]="Yankee";
Words["z"]="Zulu";
Words["0"]="Zero";
Words["1"]="One";
Words["2"]="Two";
Words["3"]="Three";
Words["4"]="Four";
Words["5"]="Five";
Words["6"]="Six";
Words["7"]="Seven";
Words["8"]="Eight";
Words["9"]="Niner";
Words["-"]="Dash";
Words["."]="Dot";
Words[" "]="[space]";
var trans="";
var regExp=/[\!@#$%^&*(),=";:
\/]/;
var stringCheck=regExp.exec(uccvt);
if(!stringCheck)
{
if
(uccvt.length > 0)
{
for(var i=0;i < uccvt.length;i++)
{
var thisChar=uccvt.charAt(i);
trans
+= Words[thisChar] + " ";
}
}
else
{
trans +="Please write something.";
}
}
else
{
trans +="You entered invalid characters. Remove them and try again.";
the porperty you pass to the function I take is a string name?
Code:
var tempval= document[theField];
is the properway to access a property of the document object by way of its associated array reference.
We all have baggage to carry in life, unfortunately for me I always get the trolley with the wonky wheel...
Code:
Youre = {
STILL_not_getting_it:function(){
alert("YOU, the original poster / thread starter NEED to POST the code and NOT a LINK.");
},
MissingThePoint:function(msg){
alert("You're missing the point. " + msg);
}
}
Youre.STILL_not_getting_it();
There is a practical thing in PsPad editor : Remove blank lines... Then your code is (not clean) and wrong !
Except an errreur of quotes in the function result, Words cannot be an array (make an alert with your Words : it contains only Zero,One...Niner) but has to be an object.
It could be define like this
Code:
var Words={};
s="Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Papa,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,X-Ray,Yankee,Zulu,Zero".split(/,/g);
for (var l=s.length,i=0;i<l;i++) Words[String.fromCharCode(i+97)]=s[i];
var t="One,Two,Three,Four,Five,Six,Seven,Eight,Niner".split(/,/g);
for (i=0;i<10;i++) Words[i]=t[i];
Words["-"]="Dash";
Words["."]="Dot";
Words[" "]="[space]";
var c='';
for (i in Words) c+=i+' => '+Words[i]+'\n';
alert(c);
Then, it's perhaps faster to avoid all the character which are not letters, digits or dots, spaces and dashs (at the end it is not to be preceded with an \) with this regexp
var rgx=/[^a-z0-9\. -]/;
Good luck !
A complement and an errata (the Zero is not the last alphanumerical character but the first numerical).
Code:
<script type="text/javascript">
var Words={};
s="Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Papa,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,X-Ray,Yankee,Zulu".split(/,/g);
for (var l=s.length,i=0;i<l;i++) Words[String.fromCharCode(i+97)]=s[i];
var t="Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Niner".split(/,/g);
for (i=0;i<10;i++) Words[i]=t[i];
Words["-"]="Dash";
Words["."]="Dot";
Words[" "]="[space]";
var c='';
for (i in Words) c+=i+' => '+Words[i]+'\n';
// alert(c); just a test to see what you do
// A new method for Strings
String.prototype.toICAOPhonetic=function(){var i,l=this.length,r='';
that=this.toLowerCase();
for (i=0;i<l;i++) r+=' '+Words[that[i]];
return r;
}
// An example with KJFK
alert("JKFK".toICAOPhonetic());
</script>
KJFK (or Kilo Juliet Foxtrot Kilo) is the METAR code for New York John Fitzgerald Kennedy Airport. It gives the weather which it makes in newYork with this simple link.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<style type="text/css">
body {background:#063}
div {display:block;width:300px;margin:0 auto;background:#063;color:#ff0}
textarea{display:block;width:240px;margin:0 auto}
p{margin:0;color:#F9F}
</style>
</head>
<body>
<div i="pge">
<fieldset><legend>ICAO Phonetic</legend>
<legend>Enter your alphanumeric text
<textarea onkeyup="document.getElementById('rsp').innerHTML=this.value.toICAOPhonetic()">
</textarea></legend>
<p> </p>
<p id="rsp"></p>
</fieldset>
</div>
<script type="text/javascript">
// A anomymous function to define the String prototype toICAOPhonetic
(function(){
var Words={};
s="Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliet,Kilo,Lima,Mike,November,Oscar,Papa,Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,X-Ray,Yankee,Zulu".split(/,/g);
for (var l=s.length,i=0;i<l;i++) Words[String.fromCharCode(i+97)]=s[i];
var t="Zero,One,Two,Three,Four,Five,Six,Seven,Eight,Nine".split(/,/g);
for (i=0;i<10;i++) Words[i]=t[i];
Words["-"]="Dash";
Words["."]="Dot";
Words[" "]="[space]";
// A new method for Strings
String.prototype.toICAOPhonetic=function(){var i,l,r='';
that=this.toLowerCase().replace(/[^a-z0-9\. -]/g,'');
l=that.length;
for (i=0;i<l;i++) r+=' '+Words[that[i]];
return r;
}
})();
</script>
</body>
</html>
Then put this code in the textarea : KJFK 211451Z 32011G20KT 10SM FEW250 34/17 A2990 RMK AO2 SLP125 T03390172 58013
You have now to find mp3 to pronounce this message (for example with dewplayer...).
NB : I make minor changes to remove all the non alphanumeric (a-z 0-9 dash, point or blank ) signs (this characters could be replace with something like ?) and to define the length after this action.
Exactly what I needed. I do have one final question that I hope you can help me with. I tried to remove the revers portion at the end of the page since I don`t want this to take up to much space and it wouldn't serve any purpose for what it is intended for. When I remove the text area from the body nothing works anymore. I have tried removing some of the associated code from the script as well but to no avail. Not sure what I am doing wrong. Either way thanks again for all of your help and for sharing your knowledge.
function tag(tagname, n){
if(n== undefined) n= 0;
return document.getElementsByTagName(tagname)[n];
}
function printJargon(){
var val, err, inp= tag('input'), outp= tag('textarea'),
val= inp.value.replace(/[^A-Za-z0-9 ,.\/:-]/g, '');
if(!/[a-zA-Z0-9]/.test(val)){
zapJargon();
alert('You need some letters or digits to convert');
inp.focus();
}
else{
outp.value= jargon(val);
tag('input').value= '';
outp.focus();
}
}
function phoneticgen(){
tag('textarea').value= '';
tag('input').value= '';
tag('input').focus();
}
window.onload= function(){
phoneticgen();
tag('button', 1).onclick= printJargon;
tag('button', 2).onclick= printJargon;}
</script>
<!-----------------------------------------------Phonetic Generator End------------------------------------------->
<SCRIPT LANGUAGE="JavaScript">
<!--
// Use the following variable to specify
// the number of random words
var NumberOfWords = 27
function BuildArray(size){
this.length = size
for (var i = 1; i <= size; i++){
this[i] = null}
return this
}
function PickRandomWord(frm) {
// Generate a random number between 1 and NumberOfWords
var rnd = Math.ceil(Math.random() * NumberOfWords)
var rannumb = Math.floor ( Math.random ( ) * 89 + 10 )
// Display the word inside the text box
frm.WordBox.value = (words[rnd]+rannumb)
}
Bookmarks