Script Categories













Equivalents >>> Morse Code.

Converts an English word or phrase into it's Morse Code combination of dots and dashes. Analyzing each letter entered individually, as this script demonstrates, is a very useful JavaScript programming technique.

Please type your phrase in plain English

Add the below code to the <body> section of your page:

<script language="javascript" type="text/javascript">
/* Visit http://www.yaldex.com/ for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin
function translate(form) {
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .,?:-!";
morse = new Array(
".-","-...","-.-.","-..",".","..-.",
"--.","....","..",".---","-.-",".-..",
"--","-.","---",".--.","--.-",".-.",
"...","-","..-","...-",".--","-..-",
"-.--","--..",".-","-...","-.-.","-..",
".","..-.","--.","....","..",".---",
"-.-",".-..","--","-.","---",".--.",
"--.-",".-.","...","-","..-","...-",
".--","-..-","-.--","--.."," ",".-.-.-",
"--..--","..--..","---...","-....-","!");

form.output.value = "";
var input = form.input.value;
output = "";
for(count = 0; count < input.length; count++) {
daChar = input.charAt(count);
for (i = 0; i < letters.length; i++) {
if (daChar == letters.charAt(i)) {
output += morse[i];
break;
      }
   }
}
form.output.value = output;
}
//  End -->
</script>
<form>
<table>
<tr>
<td
align=center>
Please type your phrase in plain English<br>
<textarea name=input cols=50 rows=4 wrap=physical></textarea>
</td>
</tr>
<tr>
<td
align=center>
<input type=button value="Translate!" onClick="javascript:translate(this.form)">
</td>
</tr>
<tr>
<td
align=center>
<textarea name=output cols=50 rows=4 wrap=physical></textarea>
</td>
</tr>
</table>
</form>

JavaScript Editor Get Advanced
JavaScript and Ajax Editor,
Validator and Debugger!

1st JavaScript Editor.



Code was highlighted by 1st JavaScript Editor (The Best JavaScript Editor!).




©