Kerberos/Cerberus

"Greek form: Κέρβερος, Cerberus was the son of Echidna, a hybrid half-woman, half-serpent and Typhon, a fire-breathing giant whom even the Olympian gods feared. Its brother is Orthrus, always depicted as a two-headed hellhound. The common depiction of Cerberus in Greek mythology and art is as having three heads, a mane of live serpents (similar to Medusa's hair) and a snake's tail. In most works the three-heads each respectively see and represent the past, the present, and the future, while other sources suggest the heads represent birth, youth, and old age. Each of Cerberus' heads is said to have an appetite only for live meat and thus allow the spirits of the dead to freely enter the underworld, but allow none to leave. Cerberus was always employed as Hades' loyal watchdog, and guarded the gates that granted access and exit to the underworld." Wikipedia
Showing posts with label Javascript. Show all posts
Showing posts with label Javascript. Show all posts

Thursday, June 3, 2010

Get Value, Index, Text on HTML Select Tag [Javascript]





  Code:

    function getSelectedIndex(id,id2){
     var indx = document.getElementById(id).selectedIndex;
     var op = document.getElementById(id2);
     op.value ="Index is: " + indx;
    }
    function getSelectedValue(id,id2){
     var val = document.getElementById(id).value;
     var op = document.getElementById(id2);
     op.value = "Value is: " + val;
    }
    function getSelectedTxt(id,id2){
     var indx = document.getElementById(id).selectedIndex;
     var txt = document.getElementById(id).options[indx].text;
     var op = document.getElementById(id2);
     op.value = "Text is: " + txt;
    }


EXAMPLE
  Structure:
INDEX
VALUE
TEXT
0
String value 1
Text 1
1
String value 2
Text 2
2
String value 3
Text 3
3
String value 4
Text 4
4
String value 5
Text 5


    Input Select Here:
     
    Output:
     

            

Wednesday, June 2, 2010

trim(), ltrim(), rtrim() [Javascript Implementation]


 rtrim, ltrimtrim are string manipulation functions
 which strip or remove whitespaces from the beginning, ending,
 or both beginning and ending of a string. 



  Code:

   function trim(id){
    var txt = document.getElementById(id);
    var str = txt.value.replace(/^\s+/, '').replace(/\s+$/, '');
    return str;
   }

   function ltrim(id){
    var txt = document.getElementById(id);
    var str = txt.value.replace(/^\s+/, '');
    return str;
   }

   function rtrim(id){
    var txt = document.getElementById(id);
    var str = txt.value.replace(/\s+$/, '');
    return str;
   }




See sample output below:
Input Text Here:

Output: