Foros del Web » Programando para Internet » PHP »

Funciones de JavaScript

Estas en el tema de Funciones de JavaScript en el foro de PHP en Foros del Web. @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original < html >     < head >       < script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js" >< / script ...
  #1 (permalink)  
Antiguo 23/10/2012, 16:44
Avatar de danramglez  
Fecha de Ingreso: septiembre-2012
Mensajes: 70
Antigüedad: 11 años, 6 meses
Puntos: 2
Funciones de JavaScript

Código HTML:
Ver original
  1.     <head>
  2.       <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
  3.       <script type="text/javascript">
  4.         $(document).ready(function() {
  5.             $('#btnAdd').click(function() {
  6.                 var num     = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
  7.                 var newNum  = new Number(num + 1);      // the numeric ID of the new input field being added
  8.  
  9.                 // create the new element via clone(), and manipulate it's ID using newNum value
  10.                 var newElem = $('#input' + num).clone().attr('id', 'input' + newNum);
  11.  
  12.                 // manipulate the name/id values of the input inside the new element
  13.                 newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name' + newNum);
  14.  
  15.                 // insert the new element after the last "duplicatable" input field
  16.                 $('#input' + num).after(newElem);
  17.  
  18.                 // enable the "remove" button
  19.                 $('#btnDel').attr('disabled','');
  20.  
  21.                 // business rule: you can only add 10 names
  22.                 if (newNum == 10)
  23.                     $('#btnAdd').attr('disabled','disabled');
  24.             });
  25.  
  26.             $('#btnDel').click(function() {
  27.                 var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
  28.                 $('#input' + num).remove();     // remove the last element
  29.  
  30.                 // enable the "add" button
  31.                 $('#btnAdd').attr('disabled','');
  32.  
  33.                 // if only one element remains, disable the "remove" button
  34.                 if (num-1 == 1)
  35.                     $('#btnDel').attr('disabled','disabled');
  36.             });
  37.  
  38.             $('#btnDel').attr('disabled','disabled');
  39.         });
  40.     </script>
  41.  
  42.      
  43.         <meta charset="utf-8" />    
  44.         <title>Ejemplo</title>  
  45.         <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />  
  46.         <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
  47.         <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>  
  48.         <link rel="stylesheet" href="/resources/demos/style.css" />  
  49.           <script>  
  50.           $(function() {    
  51.           var availableTags = [    
  52.           "ActionScript",      
  53.           "AppleScript",    
  54.           "Asp",      
  55.           "BASIC",      
  56.           "C",      
  57.           "C++",    
  58.           "Clojure",    
  59.           "COBOL",      
  60.           "ColdFusion",
  61.           "Daniel",
  62.           "Mary",  
  63.           "Erlang",        
  64.           "Fortran",    
  65.           "Groovy",    
  66.           "Haskell",  
  67.           "Java",    
  68.           "JavaScript",
  69.           "Lisp",    
  70.           "Perl",      
  71.           "PHP",      
  72.           "Python",  
  73.           "Ruby",    
  74.           "Scala",      
  75.           "Scheme"  
  76.           ];  
  77.               function split( val ) {          
  78.               return val.split( /,\s*/ );        }    
  79.               function extractLast( term ) {        
  80.               return split( term ).pop();      
  81.           }      
  82.            $( "#name" )      
  83.           // don't navigate away from the field on tab when selecting an item        
  84.           .bind( "keydown", function( event ) {          
  85.           if ( event.keyCode === $.ui.keyCode.TAB &&      
  86.           $( this ).data( "autocomplete" ).menu.active ) {  
  87.           event.preventDefault();                }            })    
  88.           .autocomplete({                minLength: 0,              
  89.           source: function( request, response ) {                
  90.           // delegate back to autocomplete, but extract the last term    
  91.           response( $.ui.autocomplete.filter(            
  92.           availableTags, extractLast( request.term ) ) );                },      
  93.           focus: function() {                
  94.           // prevent value inserted on focus          
  95.           return false;                },        
  96.           select: function( event, ui ) {              
  97.           var terms = split( this.value );  
  98.           // remove the current input                
  99.           terms.pop();                
  100.           // add the selected item            
  101.           terms.push( ui.item.value );            
  102.           // add placeholder to get the comma-and-space at the end  
  103.           terms.push( "" );                    this.value = terms.join( ", " );    
  104.           return false;                }            });    });  
  105.           </script>
  106.          
  107.     </head>
  108.  
  109.  
  110. <form id="myForm">
  111.     <div id="input1" style="margin-bottom:4px;" class="clonedInput">
  112.         Nombre:<p class="ui-widget"><label for="name"> <input type="text" class="text" name="name"value="<?php if (isset($posted['name'])) echo $posted['name']; ?>" id="name" /></label>
  113.     <div>
  114.         <input type="button" id="btnAdd" value="Agregar otro nombre" />
  115.         <input type="button" id="btnDel" value="Eliminar nombre" />
  116.     </div>
  117. </form>
  118.  
  119. </body>
  120. </html>


Hola amigos quisiera saber si puedo hacer dos funciones diferentes de javascript en un textbox, una es de autocompletar y la otra que agregue un textbox nuevo, quisiera saber si se puede y que estoy haciendo mal, mil gracias.
__________________
"La funcion de un buen software es hacerlo parecer simple"
  #2 (permalink)  
Antiguo 23/10/2012, 16:57
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Funciones de JavaScript

Hola, ¿te fijaste que este es el foro de php y no de javascript antes de escribir tu tema?

Porque deberías, te has equivocado de foro.

He reportado tu mensaje para que lo muevan de aquí.
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #3 (permalink)  
Antiguo 23/10/2012, 17:05
Avatar de danramglez  
Fecha de Ingreso: septiembre-2012
Mensajes: 70
Antigüedad: 11 años, 6 meses
Puntos: 2
Respuesta: Funciones de JavaScript

si ya lo cambie gracias
__________________
"La funcion de un buen software es hacerlo parecer simple"

Etiquetas: funciones, html, javascript
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:20.