Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    585

    controllo campi form con inserimento data

    Ciao !!
    ho questo problema:

    TEORIA:
    ho una form che contiene 2 campi input text;
    vorrei che quando uno clicca sul campo1, se esso e' vuoto (cioe' non e' stato ancora compilato) allora il campo2 e' pronto a ricevere come valore la data di sistema.
    Se invece uno clicca sul campo1 gia' compilato allora campo2 mantiene la data di sistema (ricevuta la priam volta) e non puo' essere piu' modificato.

    PRATICA:
    Ho iniziato a scrivere codice ma non funzica niente...
    Grazie mille in anticipo dell' aiuto !!

    <html>
    <head>
    <script>
    function checkvalue() {
    document.FrontPage_Form2.des2.value=="passare come valore new Date()";
    }
    </script>
    </head>

    <body>
    <form name="FrontPage_Form2" method="POST" action="test4.asp">


    <input name="des1" size="20" onclick="checkvalue()">
    <input name="des2" size="20">


    </form>
    </body>
    </html>

  2. #2
    Utente di HTML.it L'avatar di lake86
    Registrato dal
    Dec 2006
    Messaggi
    705
    assecna questa function all'onclick

    codice:
    function click(){
       var x1 = document.getElementById('des1');
       var x2 = document.getElementById('des2');
       if (x2.value == ''){
             // scrivo in text2 la data 
              var time = new Date();      
    	   // ORE
               var h = time.getHours();
    	   if (h<10) h="0"+ h;  	  
    	   // MINUTI
    	   var m =time.getMinutes();
    	    if (m<10) m= "0" + m;   
    	    // SECONDI
    	    var s = time.getSeconds();
    	    if (s<10)  s= "0" + s; 	  
    	    var tempo = " Sono le: " + h + ":" + m + ":" + s;			  
    	    x2.value= tempo ; 
       }
       x2.disabled=true;
    }

  3. #3
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    cosi:
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Esempio</title>
    <script language="JavaScript" type="text/javascript">
    function ImpostaData(){
    var scadenza = new Date()
    var gg = scadenza.getDate();
    var mm = scadenza.getMonth()+1;
    if (mm < 10) MM = "0"+mm 
    else MM = mm
    var aa = scadenza.getFullYear();
    var data = gg+"/"+MM+"/"+aa
    if(document.getElementById("text1").value =="")
    document.getElementById("text2").value=data
    else if(document.getElementById("text1").value !="")
    document.getElementById("text2").readOnly=true;
    
    }
      </script>
    </head>
    <body>
    <form id="form1" name="form1" method="post" action="">
      <label>
      <input name="text1" type="text" id="text1" onfocus="return ImpostaData()" />
      </label>
      <label>
      <input name="text2" type="text" id="text2" />
      </label>
    
    </form>
    </body>
    </html>
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  4. #4
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    585
    Vi ringrazio moltissimo dell' aiuto !!!
    Grazie a Voi ho risolto il problema in questo maniera funzionante:

    <html>

    <head>
    <script>
    function checkvalue() {
    if (document.getElementById('des1').value!='' && document.getElementById('des2').value=='') {
    document.FrontPage_Form2.des2.value=new Date(); }
    else if (document.getElementById('des3').value!='' && document.getElementById('des4').value=='') {
    document.FrontPage_Form2.des4.value=new Date(); }
    }
    </script>
    </head>

    <body>
    <form name="FrontPage_Form2" method="POST" action="test4.asp">


    <input name="des1" id="des1" size="20" onchange="checkvalue()">
    <input name="des2" id="des2" size="20" readonly="true">


    <input name="des3" id="des3" size="20" onchange="checkvalue()">
    <input name="des4" id="des4" size="20" readonly="true">



    </form>

    </body>
    </html>

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.