Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use javascript function for multiple tasks?
    text
    copied!<p>i have javascript function. i am using that function to translate english language to another language in a text field. as below form when a person type in box01, box02 shows typed english content in translated mode.</p> <pre><code> &lt;form id="txtBox" action="ps.php" enctype="multipart/form-data" method="post"&gt; &lt;textarea id="box01" onkeyup="startText_sin();" onselect="startText_sin();" onclick="startText_sin();" rows="2" placeholder ="Type in Here"&gt;&lt;/textarea&gt; &lt;textarea id="box02" rows="2" placeholder ="Translated"&gt;&lt;/textarea&gt; &lt;/form&gt; </code></pre> <p>but <strong>i have few of these forms in my single page</strong> and the text areas have diffrent names, like bellow,</p> <pre><code> &lt;textarea id="txt_sin01"&gt;&lt;/textarea&gt; &lt;textarea id="txt_trn02"&gt;&lt;/textarea&gt; </code></pre> <p>how can i can set function to be work with all of these text areas ?<br> my function is <code>**startText_sin()**</code><br></p> <p>in function i choose text area like this <code>text = document.getElementById("box01");</code></p> <p>any help.</p> <p><em><strong></em>__<em>_</em>___</strong><em>function</em><strong><em>_</em>__<em>_</em>__<em>_</em>_</strong><br></p> <p>` //array goes here</p> <p>function startText_sin() {</p> <pre><code>var s,r,v; //text = document.txtBox.box1.value; text_singlish = document.getElementById("box1_singlish").value; //special consonents for (var i=0; i&lt;specialConsonants.length; i++){ text_singlish = text_singlish.replace(specialConsonants[i], specialConsonantsUni[i]); } //consonents + special Chars for (var i=0; i&lt;specialCharUni.length; i++){ for (var j=0;j&lt;consonants.length;j++){ s = consonants[j] + specialChar[i]; v = consonantsUni[j] + specialCharUni[i]; r = new RegExp(s, "g"); text_singlish = text_singlish.replace(r, v); } } //consonants + Rakaransha + vowel modifiers for (var j=0;j&lt;consonants.length;j++){ for (var i=0;i&lt;vowels.length;i++){ s = consonants[j] + "r" + vowels[i]; v = consonantsUni[j] + "්‍ර" + vowelModifiersUni[i]; r = new RegExp(s, "g"); text_singlish = text_singlish.replace(r, v); } s = consonants[j] + "r"; v = consonantsUni[j] + "්‍ර"; r = new RegExp(s, "g"); text_singlish = text_singlish.replace(r, v); } //consonents + vowel modifiers for (var i=0;i&lt;consonants.length;i++){ for (var j=0;j&lt;nVowels;j++){ s = consonants[i]+vowels[j]; v = consonantsUni[i] + vowelModifiersUni[j]; r = new RegExp(s, "g"); text_singlish = text_singlish.replace(r, v); } } //consonents + HAL for (var i=0; i&lt;consonants.length; i++){ r = new RegExp(consonants[i], "g"); text_singlish = text_singlish.replace(r, consonantsUni[i]+"්"); } //vowels for (var i=0; i&lt;vowels.length; i++){ r = new RegExp(vowels[i], "g"); text_singlish = text_singlish.replace(r, vowelsUni[i]); } document.getElementById("box2_singlish").value=text_singlish; //wirte on page in sihala </code></pre> <p>} </p> <p>`</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload