www.webdeveloper.com
Results 1 to 12 of 12

Thread: Military Code

  1. #1
    Join Date
    Nov 2011
    Posts
    1

    Cool Military Code

    Hi there,

    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.";

    }





    document.csrAlpha.csrresult.value=trans;



    }



    //-->

    </script>












    <form name="csrAlpha">








    <script type="text/javascript">



    </script>





    <input type="text" name="csrresult2" size="70" maxlength="120">










    <input type="button" value="Translate" onclick="results();">






    <input type="Reset" value="Clear Values">







    <textarea name="csrresult" cols="20" rows="10" value="">
    </textarea>

    Any ideas of what's going on?

    Thanks!

    Louis

  2. #2
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,364
    What kind of errors are you getting when using on-line?

  3. #3
    Join Date
    Jan 2009
    Location
    Insanity
    Posts
    1,131
    Bad use of Eval.

    You SHOULD NOT be using eval() like this.
    Code:
    var tempval=eval("document."+theField)
    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();

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    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 !

  5. #5
    Join Date
    Jun 2012
    Posts
    5

    Followup

    Hi Strozzap.

    I am trying to do something very similar. Were you able to make this work?

    Please let me know how.

    Thanks a bunch!

  6. #6
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264

    NAto Phonetic Alphabet or ICAO phonetic

    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.
    Last edited by 007Julien; 06-19-2012 at 05:57 PM.

  7. #7
    Join Date
    Jun 2012
    Posts
    5

    RE: Julien

    Hey Julien

    Thank you for your reply. I took you code and added Strozzap`s form text boxes:

    <input type="text" name="csrresult2" size="70" maxlength="120">
    <input type="button" value="Translate" onclick="results();">
    <input type="Reset" value="Clear Values">
    <textarea name="csrresult" cols="20" rows="10" value="">
    </textarea>

    when I open this in a browser I get: undefined undefined undefined undefined

    here is a great example of what I am trying to achieve:
    http://www.csgnetwork.com/phonetictranslator.html

  8. #8
    Join Date
    Feb 2006
    Posts
    2,927
    This is another approach.

    Code:
    <!doctype html>
    <html lang="en">
    <head>
    <meta charset= "utf-8">
    <title>Military Jargon</title>
    <style>
    body{font-size:125%;margin:1em;}
    p, input, textarea, button{font-size:20px;font-weight:bold;}
    textarea{width:60%;min-width:400px;max-width:900px;}
    button{cursor:pointer;color:navy;}
    button:hover, button:focus{color:red;}
    </style>
    <script>
    function jargon(string){
        var A= [], tem, temp, index= 0, len,
        keys={
            ' ':'[space]', '-':'Dash', '.':'Dot', '/':'Slash', ':':'Colon', ',':'Comma',
            '0':'Zero', '1':'One', '2':'Two', '3':'Three', '4':'Four', '5':'Five', '6':'Six',
            '7':'Seven', '8':'Eight', '9':'Nine', 'a':'Alpha', 'b':'Bravo', 'c':'Charlie',
            'd':'Delta', 'e':'Echo', 'f':'Foxtrot', 'g':'Golf', 'h':'Hotel', 'i':'India',
            'j':'Juliet', 'k':'Kilo', 'l':'Lima', 'm':'Mike', 'n':'November', 'o':'Oscar',
            'p':'Papa', 'q':'Quebec', 'r':'Romeo', 's':'Sierra', 't':'Tango', 'u':'Uniform',
            'v':'Victor', 'w':'Whiskey', 'x':'X-Ray', 'y':'Yankee', 'z':'Zulu'
        }
        if(string=== true) return keys;
        string= string.replace(/[^A-Za-z0-9 ,.\/:-]/g, '').replace(/([ \/:,-]) +/g, '$1').replace(/(\d)\. +(\d)/g, '$1.$2');
        len= string.length;
        while(index<len){
            tem= string.charAt(index++) || '';
            if(tem){
                temp= keys[tem.toLowerCase()] || '';
                if(tem!== tem.toLowerCase()) temp= temp.toUpperCase();
                A.push(temp);
            }
        }
        return A.join(' ');
    }
    function fromJargon(string){
        var len, index= 0, tem, A= [], keys= {},
        k= jargon(true);
        for(var p in k){
            if(k.hasOwnProperty(p)){
                keys[k[p]]= p;
                if(/[a-z]/.test(p)){
                    keys[k[p].toUpperCase()]= p.toUpperCase();
                }
            }
        }
        string= string.split(/\s+/);
        len= string.length;
        while(index<len){
            tem= string[index++];
            A.push(keys[tem] || '');
        }
        return A.join('');
    }
    
    
    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', 1).value= '';
            outp.focus();
        }
    }
    function printReverse(){
        var temp, val= tag('textarea').value, inp= tag('input');
        if(val){
            temp= fromJargon(val);
            tag('input', 1).value= temp;
            if(!temp){
                alert('Only military jargon will be converted');
                return zapJargon();
            }
            if(temp!== inp.value) inp.value= temp;
            tag('input', 1).focus();
        }
    }
    function zapJargon(){
        tag('textarea').value= '';
        tag('input').value= '';
        tag('input', 1).value= '';
        tag('input').focus();
    }
    window.onload= function(){
        zapJargon();
        tag('input').value= 'John T. Smith born 10-10-1978';
        tag('button').onclick= printJargon;
        tag('button', 1).onclick= zapJargon;
        tag('button', 2).onclick= printReverse;
    }
    </script>
    </head>
    <body>
    <h1>Military Jargon</h1>
    <p>Plain Text: <input type="text" size="60" value="John T. Smith born 10-10-1978"></p>
    <p><button type="button">to Jargon</button> <button type="button">Clear</button></p><br>
    <textarea rows="6" ></textarea>
    </p>
    <p>Reverse: <button type="button">From Jargon</button>
    <p><input type="text" size="60" readonly></p>
    </body>
    </html>

  9. #9
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    Try this
    Code:
    <!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>&nbsp;</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.
    Last edited by 007Julien; 06-21-2012 at 10:44 AM.

  10. #10
    Join Date
    Jun 2012
    Posts
    5

    RE: Julien

    Thank you, thank you, thank you!

    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.

    Marty.

  11. #11
    Join Date
    Jun 2012
    Posts
    5

    Figured it out but...

    OK I figured it out but now when I past the code into another page it doesnt work anymore. Here is the code.

    <html>
    <head>
    <LINK href="stylefonts.css" type=text/css rel=stylesheet>
    <title>Quick Links</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <!-------------------------------------------------Phonetic Generator----------------------------------------------->
    <script>
    function jargon(string){
    var A= [], tem, temp, index= 0, len,
    keys={
    ' ':'[space]', '-':'Dash', '.':'Dot', '/':'Slash', ':':'Colon', ',':'Comma',
    '0':'Zero', '1':'One', '2':'Two', '3':'Three', '4':'Four', '5':'Five', '6':'Six',
    '7':'Seven', '8':'Eight', '9':'Nine', 'a':'Alpha', 'b':'Bravo', 'c':'Charlie',
    'd':'Delta', 'e':'Echo', 'f':'Foxtrot', 'g':'Golf', 'h':'Hotel', 'i':'India',
    'j':'Juliet', 'k':'Kilo', 'l':'Lima', 'm':'Mike', 'n':'November', 'o':'Oscar',
    'p':'Papa', 'q':'Quebec', 'r':'Romeo', 's':'Sierra', 't':'Tango', 'u':'Uniform',
    'v':'Victor', 'w':'Whiskey', 'x':'X-Ray', 'y':'Yankee', 'z':'Zulu'
    }
    if(string=== true) return keys;
    string= string.replace(/[^A-Za-z0-9 ,.\/:-]/g, '').replace(/([ \/:,-]) +/g, '$1').replace(/(\d)\. +(\d)/g, '$1.$2');
    len= string.length;
    while(index<len){
    tem= string.charAt(index++) || '';
    if(tem){
    temp= keys[tem.toLowerCase()] || '';
    if(tem!== tem.toLowerCase()) temp= temp.toUpperCase();
    A.push(temp);
    }
    }
    return A.join(' ');
    }
    function fromJargon(string){
    var len, index= 0, tem, A= [], keys= {},
    k= jargon(true);
    for(var p in k){
    if(k.hasOwnProperty(p)){
    keys[k[p]]= p;
    if(/[a-z]/.test(p)){
    keys[k[p].toUpperCase()]= p.toUpperCase();
    }
    }
    }
    string= string.split(/\s+/);
    len= string.length;
    while(index<len){
    tem= string[index++];
    A.push(keys[tem] || '');
    }
    return A.join('');
    }


    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

    var words = new BuildArray(NumberOfWords)

    // Use the following variables to
    // define your random words:
    words[1] = "Aliant"
    words[2] = "Sunday"
    words[3] = "Quebec"
    words[4] = "Sunset"
    words[5] = "Friday"
    words[6] = "Monday"
    words[7] = "Soccer"
    words[8] = "Tennis"
    words[9] = "Hockey"
    words[10] = "Winter"
    words[11] = "Canada"
    words[12] = "Summer"
    words[13] = "United"
    words[14] = "August"
    words[15] = "Orange"
    words[16] = "Island"
    words[17] = "Ottawa"
    words[18] = "Regina"
    words[19] = "Acadia"
    words[20] = "Coffee"
    words[21] = "Copper"
    words[22] = "Spring"
    words[23] = "Desert"
    words[24] = "Yellow"
    words[25] = "Violet"
    words[26] = "Office"
    words[27] = "Oxford"


    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)
    }

    //-->
    </SCRIPT>
    <style type="text/css">
    textarea{
    width:100%;
    min-width:100px;
    max-width:500px;
    border:none;
    overflow:hidden
    }

    /*---------------------------NB Ticket assignment tool tip-------------------------*/
    * {
    font-family:Verdana, Arial, Helvetica, sans-serif;
    font-size:11px;
    text-decoration: none;
    color: #000000;
    }
    a:hover {background:#ffffff; text-decoration:none;} /*BG color is a must for IE6*/
    a.tooltip span {
    display:none;
    margin-left:-700px;
    width:400px;
    margin-top: -200px;
    padding-top: 5px;
    padding-right: 3px;
    padding-bottom: 2px;
    padding-left: 5px;
    }
    a.tooltip:hover span{
    display:inline;
    position:absolute;
    border:1px solid #cccccc;
    background:#ffffff;
    }
    /*--------------------------------Tool tip end-------------------------------------*/
    #header {
    font-family: Tahoma, Geneva, sans-serif;
    font-size: 18px;
    line-height: 30px;
    color: #000000;
    font-style: normal;
    min-width: 300px;
    height: 30px;
    padding-top: 2px;
    padding-left: 5px;
    width: 100%;
    border-bottom-width: 1px;
    border-bottom-style: dotted;
    border-bottom-color: #000000;
    }
    form {
    margin: 0px;
    color: #000;
    min-width: 300px;
    padding-top: 0px;
    padding-right: 0px;
    padding-bottom: 0px;
    padding-left: 0px;
    }
    .button {
    color: #000;
    font-weight: lighter;
    }
    body {
    margin-left: 0px;
    color: #333;
    font-family: Tahoma, Geneva, sans-serif;
    padding-left: 20px;
    }
    body h1 {
    font-family: Tahoma, Geneva, sans-serif;
    font-size: 24px;
    text-decoration: none;
    text-transform: none;
    line-height: 40px;
    }
    body p {
    color: #000000;
    text-decoration: underline;
    font-weight: normal;
    margin-bottom: -15px;
    margin-top: 5px;
    }
    body a:link {
    color: #990000;
    text-decoration: none;
    font-size: 14px;
    }
    body a:hover {
    text-decoration: underline;
    }
    body a:visited {
    color: #990000;
    text-decoration: none;
    font-size: 14px;
    }
    #left_table {
    float: left;
    width: 50%;
    }
    #devider {
    float: left;
    width: 30px;
    }
    #right_table {
    width: 100%;
    }
    </style>
    </head>
    <body link="#990000" vlink="#990000" alink="#990000">
    <div id="left_table"><table width="100%" height="107" border="0" cellpadding="5" cellspacing="0">
    <tr>
    <td height="37" colspan="2" align="left" valign="bottom"><div id="header"> Password &amp; Phonetic Generator</div></td>
    </tr>
    <tr>
    <td width="40%" height="33" valign="middle"><FORM NAME="WordForm">
    <input type=BUTTON class="button" onClick="PickRandomWord(document.WordForm)"
    value="Generate" />
    <input type=TEXT name="WordBox" size="15" />
    </FORM></td>
    <td width="60%" height="33" valign="middle"><button type="button">Client Code</button>
    <input type="text" size="20"></td>
    </tr>
    <tr>
    <td height="37" colspan="2" align="left" valign="bottom"><textarea name="textarea" rows="2" ></textarea></td>
    </tr>
    </table>
    </div>
    <div id="devider">
    <table width="10" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    </div>
    </body>
    </html>

  12. #12
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,264
    A variant on this page...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles