Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    Selezionare campo e automaticamente disabilitarne un'altro

    Ciao a tutti,

    ho 2 problemi:

    Ho un form con 2 campi (CODICE + CODICE A BARRE)per la ricerca di articoli.
    1) Devo dare il focus al campo CODICE e automaticamente disabilitare il campo CODICE A BARRE e viceversa.

    2) Ho creato un piccolo tastierino numerico che scrive però soltanto sul campo CODICE e non so come poterlo settare in modo da scrivere dove c'è il focus.

    Codice PHP:
    <html>

    <
    head>
    <
    meta http-equiv="Content-Language" content="it">
    <
    meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <
    title>Info Prezzi</title>
    </
    head>

    <
    body>


    <
    div align="center">
    <
    table border="1" width="360" id="table2" height="300" style="border-collapse: collapse">
    <
    tr>
    <
    form name="InfoPrezzi" method="POST" action="CercaPrezzi.asp">
    <
    td valign="top">
    <
    table border="0" width="100%" id="table3">
    <
    tr>
    <
    td width="35%"><font face="Arial" size="2">[b]
    CODICE INTERNO[/b]</font></td>
    <
    td width="63%">
    <
    input type="text" name="CODICE" size="6" style="font-size: 14pt; font-family: Arial"></td>
    </
    tr>
    <
    tr>
    <
    td width="35%"><font face="Arial" size="2">[b]CODICE A BARRE[/b]</font></td>
    <
    td width="63%">
    <
    input type="text" name="CODICEABARRE" size="20" style="font-size: 14pt; font-family: Arial"></td>
    </
    tr>
    <
    tr>
    <
    td colspan="2" align="center">
    <
    table border="1" width="230" id="table4">
    <
    tr>
    <
    td width="51">
    <
    input type="button" name="7" value="7" onClick="form.CODICE.value += '7'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="51">
    <
    input type="button" name="8" value="8" onClick="form.CODICE.value += '8'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="50">
    <
    input type="button" name="9" value="9" onClick="form.CODICE.value += '9'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td rowspan="2" width="50">
    <
    button name="Canc" onClick="form.CODICE.value = ''" style="width: 50px; height: 110px" value="C">
    <
    font size="5">[b]C[/b]</font></button>
    </
    td>
    </
    tr>
    <
    tr>
    <
    td width="51">
    <
    input type="button" name="4" value="4" onClick="form.CODICE.value += '4'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="51">
    <
    input type="button" name="5" value="5" onClick="form.CODICE.value += '5'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="50">
    <
    input type="button" name="6" value="6" onClick="form.CODICE.value += '6'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    </
    tr>
    <
    tr>
    <
    td width="51">
    <
    input type="button" name="1" value="1" onClick="form.CODICE.value += '1'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="51">
    <
    input type="button" name="2" value="2" onClick="form.CODICE.value += '2'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="50">
    <
    input type="button" name="3" value="3" onClick="form.CODICE.value += '3'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td rowspan="2" width="50">
    <
    button name="Space" onClick="form.CODICE.value += ' '" style="width: 50px; height: 110px" value="SP">
    [
    b]<font size="5">SP</font>[/b]</button>
    </
    td>
    </
    tr>
    <
    tr>
    <
    td width="51">
    <
    input type="button" name="0" value="0" onClick="form.COD.value += '0'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="51">
    <
    input type="button" name="00" value="00" onClick="form.COD.value += '00'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    <
    td width="50">
    <
    input type="button" name="." value="." onClick="form.COD.value += '.'" style="color: #000000; background-color: #C0C0C0; height: 50 px; width: 50 px; font-size: 18 pt; font-weight: bold"></td>
    </
    tr>
    <
    tr>
    <
    td colspan="4">
    <
    input type="submit" value="CERCA" style="color: #000000; background-color: #C0C0C0; height: 50; width: 221; font-size: 18 pt; font-weight: bold"></td>
    </
    tr>
    </
    table>
    </
    td>
    </
    tr>
    <
    tr>
    <
    p align="center"></td>
    </
    tr>
    </
    table>
    </
    td>
    <
    input type="hidden" name="Azione" value="SI">
    </
    form>
    </
    tr>
    </
    table>
    </
    div>


    </
    body>

    </
    html
    Pippo Giacalone
    giacalone@tin.it

  2. #2
    per il primo problema ho risolto così:

    <input onclick="document.getElementById(CODICEABARRE).dis abled=true;" type="text" name="CODICE" size="6" style="font-size: 14pt; font-family: Arial">

    <input onclick="document.getElementById(CODICE).disabled= true;" type="text" name="CODICEABARRE" size="20" style="font-size: 14pt; font-family: Arial">

    mi rimane adesso poter cambiare questo pezzo di codice:
    onClick="form.CODICE .value += '1'

    in questo momento all'onclick scrive 1 sul campo CODICE, io invece vorrei potermi spostare sul campo CODICEABARRE e lui scriva su quel campo ... è possibile ?
    Pippo Giacalone
    giacalone@tin.it

  3. #3
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Cosi fa quanto vuoi, per semplicità ho utilizzato ajax la pagina "ricerca.html" carica o la pagina "barre.html" oppure la pagina "code.html" e disabilita il campo senza fuoco code:
    pagina ricerca.html
    codice:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Language" content="it">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Info Prezzi</title>
    <script type="text/javascript" language="JavaScript">
    function objAjx(){
    	    var xmlhttp = null;
        	
    	    if(window.XMLHttpRequest) 
    	    {
    		    xmlhttp = new XMLHttpRequest(); // Gecko (Firefox, Moz), KHTML (Konqueror, Safari), Opera, Internet Explorer 7
    	    } 
    	    else if(window.ActiveXObject) 
    	    {
    		    try
    		    {
    			    xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); // Internet Explorer 6 
    		    } 
    		    catch(e) 
    		    {
    			    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // Internet Explorer 4,5 
    		    }
    		    } 
    	    else 
    	    {
    		    xmlhttp = null;
    	    }
    	    return xmlhttp;
        };
    		function Visualizza(pagina){
    			
    		AjaX = objAjx();
             if(AjaX){
               //Chiamo la funzione caricoRisultati quando c'è un cambio evento    
                  AjaX.onreadystatechange=function(){
                     mostroRisultati(AjaX,pagina)
                  }
                  
               //Invio i dati alla pagina .asp
                  AjaX.open('GET', pagina+"?noCache=" + new Date().getSeconds() + '' + Math.floor(Math.random() * (9999)), true)         
                  AjaX.send(null)                                      
        }
     }
       function mostroRisultati(AjaX,pagina){
       //Se è andato tutto bene faccio vedere il risultato
          if (AjaX.readyState == 4 && (AjaX.status==200 || window.location.href.indexOf("http")==-1)){
            document.getElementById("tastierino").innerHTML = AjaX.responseText
    		
    }
    }
    </script>
    </head>
    
    <body>
    
    
    <div align="center">
    <table border="1" width="360" id="table2" height="300" style="border-collapse: collapse">
    <tr>
    <form name="InfoPrezzi" method="POST" action="CercaPrezzi.asp">
    <td valign="top">
    <table border="0" width="100%" id="table3">
    <tr>
    <td width="35%"><font face="Arial" size="2">
    CODICE INTERNO</font></td>
    <td width="63%">
    <input type="text" name="CODICE" id="code" onfocus="Visualizza('code.html'); form.CODICEABARRE.disabled=true" size="20" style="font-size: 14pt; font-family: Arial"></td>
    </tr>
    <tr>
    <td width="35%"><font face="Arial" size="2">CODICE A BARRE</font></td>
    <td width="63%">
    <input type="text" name="CODICEABARRE" id="barre" size="20" style="font-size: 14pt; font-family: Arial" onfocus="Visualizza('barre.html'); form.CODICE.disabled=true" ></td>
    </tr>
    <tr>
    <td colspan="2" align="center" id="tastierino">Per inziare la ricerca clicca in uno dei campi</td>
    </table>
    <input type="hidden" name="Azione" value="SI">
    </form>
    </table>
    </div>
    
    
    </body>
    
    </html>
    pagina da salvare con nome code.html
    codice:
    <table border="1" width="161" id="table4">
      <tr>
        <td width="23"><input type="button" name="7" value="7" onClick="document.getElementById('code').value += '7'" ></td>
        <td width="30"><input type="button" name="8" value="8" onClick="document.getElementById('code').value += '8'" ></td>
        <td width="23"><input type="button" name="9" value="9" onClick="document.getElementById('code').value += '9'" ></td>
        <td width="126"><input type="button" name="Canc" onclick="document.getElementById('code').value = ''" value="C" /></td>
      </tr>
      <tr>
        <td width="23"><input type="button" name="4" value="4" onClick="document.getElementById('code').value += '4'" ></td>
        <td width="30"><input type="button" name="5" value="5" onClick="document.getElementById('code').value += '5'" ></td>
        <td width="23"><input type="button" name="6" value="6" onClick="document.getElementById('code').value += '6'" ></td><td><input type="button" name="Space" onclick="document.getElementById('code').value += ' '" value="SP" /></td>
      </tr>
      <tr>
        <td width="23"><input type="button" name="1" value="1" onClick="document.getElementById('code').value += '1'" ></td>
        <td width="30"><input type="button" name="2" value="2" onClick="document.getElementById('code').value += '2'" ></td>
        <td width="23"><input type="button" name="3" value="3" onClick="document.getElementById('code').value += '3'"></td>
        <td width="126"><input type="button" name="reset" id="reset" value="Resetta" onclick="if( confirm('Sicuro di voler resettare il form?'))location.reload(true)" /></td>
      </tr>
      <tr>
        <td width="23"><input type="button" name="0" value="0" onClick="document.getElementById('code').value += '0'" ></td>
        <td width="30"><input type="button" name="00" value="00" onClick="document.getElementById('code').value += '00'" ></td>
        <td width="23"><input type="button" name="." value="." onClick="document.getElementById('code').value += '.'" ></td><td><input name="Pulsante" type="button" value="CERCA" onclick="document.forms['InfoPrezzi'].submit()" /></td>
      </tr>
    </table>
    pagina da salvare con nome barre.html
    codice:
    <table border="1" width="161" id="table4">
      <tr>
        <td width="23"><input type="button" name="7" value="7" onClick="document.getElementById('barre').value += '7'" ></td>
        <td width="30"><input type="button" name="8" value="8" onClick="document.getElementById('barre').value += '8'" ></td>
        <td width="23"><input type="button" name="9" value="9" onClick="document.getElementById('barre').value += '9'" ></td>
        <td width="126"><input type="button" name="Canc" onclick="document.getElementById('barre').value = ''" value="C" /></td>
      </tr>
      <tr>
        <td width="23"><input type="button" name="4" value="4" onClick="document.getElementById('barre').value += '4'" ></td>
        <td width="30"><input type="button" name="5" value="5" onClick="document.getElementById('barre').value += '5'" ></td>
        <td width="23"><input type="button" name="6" value="6" onClick="document.getElementById('barre').value += '6'" ></td><td><input type="button" name="Space" onclick="document.getElementById('barre').value += ' '" value="SP" /></td>
      </tr>
      <tr>
        <td width="23"><input type="button" name="1" value="1" onClick="document.getElementById('barre').value += '1'" ></td>
        <td width="30"><input type="button" name="2" value="2" onClick="document.getElementById('barre').value += '2'" ></td>
        <td width="23"><input type="button" name="3" value="3" onClick="document.getElementById('barre').value += '3'"></td>
        <td width="126"><input type="button" name="reset" id="reset" value="Resetta" onclick="if( confirm('Sicuro di voler resettare il form?'))location.reload(true)" /></td>
      </tr>
      <tr>
        <td width="23"><input type="button" name="0" value="0" onClick="document.getElementById('barre').value += '0'" ></td>
        <td width="30"><input type="button" name="00" value="00" onClick="document.getElementById('barre').value += '00'" ></td>
        <td width="23"><input type="button" name="." value="." onClick="document.getElementById('barre').value += '.'" ></td><td><input name="Pulsante" type="button" value="CERCA" onclick="document.forms['InfoPrezzi'].submit()" /></td>
      </tr>
    </table>
    Attenzione se cambi i nomi delle pagina barre e code dovrai aggiornare anche i rispettivi campi. ho cancellato tutti gli stile in linea era un casino non si capiva niente se vuoi cambiare lo stile usa i css impostando un foglio di stile esterno
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

  4. #4
    Grazie Cavicchiandrea,

    e se volessi fare partire di default una delle 2 pagine ?
    Pippo Giacalone
    giacalone@tin.it

  5. #5
    Moderatore di Annunci siti web, Offro lavoro/collaborazione, Cerco lavoro L'avatar di cavicchiandrea
    Registrato dal
    Aug 2001
    Messaggi
    26,133
    Originariamente inviato da peppeweb
    Grazie Cavicchiandrea,

    e se volessi fare partire di default una delle 2 pagine ?
    Avevo provato al caricamento d'impostare uno dei due campi, ma l'utilizzo del "fuoco" complica di molto l'operazione (senza garanzia di riuscita)
    Cavicchi Andrea
    Problemi con javascript, jquery, ajax clicca qui

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.