Advertisement
Guest User

Untitled

a guest
May 30th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.54 KB | None | 0 0
  1. <!-- script pour empecher plus de x caractères dans une textarea -->
  2. <script language="JavaScript">
  3.     function CaracMax(texte, max)
  4.     {
  5.         if (texte.value.length >= max)
  6.         {
  7.         alert('Pas plus de ' + max + ' caractère(s) !!!') ;
  8.         texte.value = texte.value.substr(0, max - 1) ;
  9.         }
  10.     }
  11. </script>
  12.  
  13.    
  14.    
  15.  
  16.         <SCRIPT language="Javascript" type="text/javascript">  
  17.         function insertion(repdeb, repfin) {
  18.                       var input = document.forms['taper_mp'].elements['VoirLogin'];
  19.                       input.focus();
  20.                       /* pour l'Explorer Internet */
  21.                       if(typeof document.selection != 'undefined') {
  22.                         /* Insertion du code de formatage */
  23.                         var range = document.selection.createRange();
  24.                         var insText = range.text;
  25.                         range.text = repdeb + insText + repfin;
  26.                         /* Ajustement de la position du curseur */
  27.                         range = document.selection.createRange();
  28.                         if (insText.length == 0) {
  29.                           range.move('character', -repfin.length);
  30.                         } else {
  31.                           range.moveStart('character', repdeb.length + insText.length + repfin.length);
  32.                         }
  33.                         range.select();
  34.                       }
  35.                       /* pour navigateurs plus récents basés sur Gecko*/
  36.                       else if(typeof input.selectionStart != 'undefined')
  37.                       {
  38.                         /* Insertion du code de formatage */
  39.                         var start = input.selectionStart;
  40.                         var end = input.selectionEnd;
  41.                         var insText = input.value.substring(start, end);
  42.                         input.value = input.value.substr(0, start) + repdeb + insText + repfin + input.value.substr(end);
  43.                         /* Ajustement de la position du curseur */
  44.                         var pos;
  45.                         if (insText.length == 0) {
  46.                           pos = start + repdeb.length;
  47.                         } else {
  48.                           pos = start + repdeb.length + insText.length + repfin.length;
  49.                         }
  50.                         input.selectionStart = pos;
  51.                         input.selectionEnd = pos;
  52.                       }
  53.                       /* pour les autres navigateurs */
  54.                       else
  55.                       {
  56.                         /* requête de la position d'insertion */
  57.                         var pos;
  58.                         var re = new RegExp('^[0-9]{0,3}$');
  59.                         while(!re.test(pos)) {
  60.                           pos = prompt("Insertion à la position (0.." + input.value.length + "):", "0");
  61.                         }
  62.                         if(pos > input.value.length) {
  63.                           pos = input.value.length;
  64.                         }
  65.                         /* Insertion du code de formatage */
  66.                         var insText = prompt("Veuillez entrer le texte à formater:");
  67.                         input.value = input.value.substr(0, pos) + repdeb + insText + repfin + input.value.substr(pos);
  68.                       }
  69.                       input.focus();
  70.                     }
  71.                
  72.           </SCRIPT>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement