Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1719 connectés 

  FORUM HardWare.fr
  Programmation
  HTML/CSS

  [javascript] Textbox expander

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[javascript] Textbox expander

n°780674
dalida
Yolanda Christina Gigliotti
Posté le 28-06-2004 à 16:15:22  profilanswer
 

Voilà, j'ai trouvé une fonction javascript toute bien pour étendre les input text au fur et à mesure que l'on écrit.
Le pb tout con que je rencontre, c'est que la fonction est écrit pour étendre un input ayant le nom "thebox" et que je voudrais envoyer plutot en paramètre le nom de l'input à étendre pour l'appliquer à des input ayant des noms différents. Ca doit être simple mais j'y arrive pas :sweat:  
j'ai essayé en mettant function boxexpand(thebox) et en passant le nom de l'input à l'appel de la fonction mais non c'est pas du tout comme ça que ça marche le javascript :sweat:  
Si vous pouvez me donner une ptite piste sur ce que je doit changer?
quand on écrit "document.all.thebox.value.length" thebox ne peut pa être une variable si?

Citation :


<!-- TWO STEPS TO INSTALL TEXTBOX EXPANDER:
 
 
 
  1.  Copy the coding into the HEAD of your HTML document
 
  2.  Add the last code into the BODY of your HTML document  -->
 
 
 
<!-- STEP ONE: Paste this code into the HEAD of your HTML document  -->
 
 
 
<HEAD>
 
 
 
<!-- This script and many more are available free online at -->
 
<!-- The JavaScript Source!! http://javascript.internet.com -->
 
<!-- Original:  Michael P. Hemmes (trueluck3@hotmail.com ) -->
 
<!-- Web Site:  TextBox Expander  -->
 
 
 
<script>
 
// The following script was written by: Michael P. Hemmes (trueluck3@hotmail.com)
 
// This script is freeware.  You may use it, change it, add to it.
 
// I don't even care if you give me credit or not (I do, however, appreciate credit)
 
// However, DO NOT change this script and leave my name credited to the changed script.
 
 
 
function boxexpand()
 
{
 
// Code to make the script easier to use //
 
boxValue=document.all.thebox.value.length
 
boxSize=document.all.thebox.size
 
minNum=20 // Set this to the MINIMUM size you want your box to be.
 
maxNum=100 // Set this to the MAXIMUM size you want your box to be.
 
 
 
// Starts the main portion of the script //
 
if (boxValue > maxNum)
 
  {
 
  }
 
else
 
{
 
 
 
  if (boxValue > minNum)
 
    {
 
      document.all.thebox.size = boxValue
 
    }
 
  else if (boxValue < minNum || boxValue != minNum)
 
    {
 
      document.all.thebox.size = minNum
 
    }
 
}
 
}

 
// End of script //
 
</script>
 
 
 
 
 
</HEAD>
 
 
 
<!-- STEP TWO: Copy this code into the BODY of your HTML document  -->
 
 
 
<BODY>
 
 
 
<!-- This script and many more are available free online at -->
 
<!-- The JavaScript Source!! http://javascript.internet.com -->
 
<!-- Original:  Michael P. Hemmes (trueluck3@hotmail.com ) -->
 
<!-- Web Site:  TextBox Expander  -->
 
 
 
<form method="POST" action="_vti_bin/shtml.dll/expand.htm" webbot-action="--WEBBOT-SELF--">
 
  <p><input type="text" onKeypress="boxexpand()" name="thebox" size=20><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
 
</form>
 
 
 
<p><center>
 
<font face="arial, helvetica" size"-2">Free JavaScripts provided<br>
 
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
 
</center><p>
 
 
 
<!-- Script Size:  2.16 KB -->


 
j'ai aussi testé en remplaçant document.all.thebox par this dans la fonction et en passant le nom du input à l'appel mais rien [:sisicaivrai]


Message édité par dalida le 28-06-2004 à 16:20:51
mood
Publicité
Posté le 28-06-2004 à 16:15:22  profilanswer
 

n°780794
fxoxo
Posté le 28-06-2004 à 17:34:29  profilanswer
 

Bon, il est pas très joli ton script ...
Commence déja par différencier les navigateurs (la méthode document.all. ne marche pas avec tous)
il faut faire des test style:
 if (document.all) {//si le navigateur comprend cette méthode    }
 else if (document.getElementById) {//sinon, si le site comprend cette autre méthode  }
 
Cherche sur le net pour avoir un script de detection de navigateur.
 
Sinon, pour passer ton paramètre:
<input type="text" onKeypress="boxexpand()" id="le_nom"  size=20>
car name est pas W3C, c'est de la vieille facon de programmer
 
En suite pour acceder aux propriètès tu fais document.getElementById("le_nom" ) (ou document.all["le_nom"])
 
 
Ramené à ton script ca devrait faire:
 
<input type="text" onKeypress="boxexpand('truc1')" id="truc1"  size=20>
 
function boxexpand(id_nom)
{
 
// Code to make the script easier to use //
 
boxValue=document.getElementById(id_nom).value.length
boxSize=document.getElementById(id_nom).size  
...
 
 
 
 

n°780819
dalida
Yolanda Christina Gigliotti
Posté le 28-06-2004 à 17:48:31  profilanswer
 

thx c parfait :)


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  HTML/CSS

  [javascript] Textbox expander

 

Sujets relatifs
[JAVASCRIPT] refresh d'une iframe dans un <div>Recupération d'un champ style "toto[1]" dans une fonction javascript
[Résolu][JavaScript]Copy to ClipBoard[Résolu][JavaScript]Probleme de Iframe + refresh
[Acrobat Javascript] ouvrir une URL dans une nouvelle fenetrePassage de variable entre 2 langages : JavaScript et CGI - C
[JAVASCRIPT] menu déroulant[Resolu] message d'erreur en javascript
[Javascript] Desactiver l'affichage du cmd[JavaScript]Probleme de "ciblage" d'un élément
Plus de sujets relatifs à : [javascript] Textbox expander


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR