Visualizzazione dei risultati da 1 a 8 su 8
  1. #1
    Utente di HTML.it
    Registrato dal
    Aug 2006
    Messaggi
    833

    Sostituzione del carattere invio con uno spazio

    Ciao a tutti. Volevo chiedervi come posso gestire una situazione.
    In pratica ho una pagina php dove immetto dei dati, poi con questi dati scrivo un file del
    Iseries che come database ha il DB2.

    Il problema e' che in una textarea con 5 righe devo togliere la possibilita' all'utente di premere invio, perche' nel db2 non e' un carattere accettato.

    Ora e qui' e' la mia domanda come posso fare in modo che quando si prema invio non succeda niente o al massimo metta uno spazio? mi dite come posso fare perche' con il controllo che c'e' adesso:
    <script language="Javascript">

    function verificacaratteri(campo)
    {
    var chiffres = new RegExp("[a-z-A-Z-0-9,-?\/*\r\n.:;*()?!%@#§àùè+ ]");
    var verif;
    var points = 0;

    for(x = 0; x < campo.value.length; x++)
    {
    verif = chiffres.test(campo.value.charAt(x));
    if(campo.value.charAt(x) == "."){points++;}
    if(points > 1){verif = false; points = 1;}
    if(verif == false){campo.value = campo.value.substr(0,x) + campo.value.substr(x+1,campo.value.length-x+1); x--;}
    }

    }
    </script>


    Se tolgo da questo controllo il carattere \n va in cpf tutto Iexplorer.
    Ciao grazie.

  2. #2
    Penso di aver capito qual'è il tuo problema! In poche parole devi trapparti l'evento keyup! Per fare questo .. da qualche parte scrivi questo codice!
    Codice PHP:
    document.onkeyup KeyCheck
    ok ... adesso abbiamo trappato l'evento di qualcuno che schiaccia un qualsiasi carattere, adesso dobbiamo crearci una funzione appunto KeyCheck che ci permetterà di filtrare la pressione dei vari tasti!

    Codice PHP:
    function KeyCheck(e)
        {
             var 
    KeyID = (window.event) ? event.keyCode e.keyCode;
            
    //alert(KeyID);
            
    switch (KeyID)
                {
                                   case 
    //qui ci va il valore numerico del tasto invio in ascii
                                       
    break;
                }
        } 
    Sperando di essere stato chiaro e di aiuto ... buon lavoro!

  3. #3
    Utente di HTML.it
    Registrato dal
    Aug 2006
    Messaggi
    833
    Grazie per la risposta. Ma essendo un neofita non ho la minima idea di come trasformare questo tuo suggerimento, "case //qui ci va il valore numerico del tasto invio in ascii", in pratica.

    Allora da quello che ho capito devo fare cosi':

    <?php print '<textarea name="customerSRVMOT" rows="5" cols="61" onkeyup=conta(this.form);verificacaratteri(this);document.onkeyup = KeyCheck; >'.$customerSRVMOT.'</textarea>';


    E poi mettere il controllo che mi hai postato:

    <script type="text/javascript">
    function KeyCheck(e)
    {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    //alert(KeyID);
    switch (KeyID)
    {
    case //qui ci va il valore numerico del tasto invio in ascii
    break;
    }
    }

    </script>


    Pero' ammesso che fino a qua' e' giusto non so come gestire il fatto che sia stato premuto invio!


    Avevo provato anche ha trasformare l'invio (\n, sperando che sia questo) in un carattere blanks, solo che l'invio lo scrive lo stesso e poi aggiunge, non trasforma, un blanks

  4. #4
    Ovviamente devi cambiare il nome del form e dell'oggetto! Poi cerca di capire cosa fa il codice !
    Questo codice già funziona, probabilmente ci sono modi più eleganti per fare la stessa cosa, ma io questa conosco
    Buon lavoro!
    codice:
    <form name="abcd">
    <textarea id="ciccio" name="ciccio" rows="5"></textarea>
    </form>
    <script language="javascript">
    document.abcd.ciccio.onkeyup = KeyCheck;
    function KeyCheck(e)
    	{
    		var KeyID = (window.event) ? event.keyCode : e.keyCode;
    		//alert(KeyID);
    		switch (KeyID)
    			{
                                    case 10:
    				case 13:
    					var str = new String(document.abcd.ciccio.value);
    					var len = str.length;
    					len--;
    					document.ciccio.value=document.ciccio.value.substr(0,len);
    				break;
    			}
    	}
    </script>

  5. #5
    Utente di HTML.it
    Registrato dal
    Aug 2006
    Messaggi
    833
    Colpa mia, non so come metterlo, posto la pagina cosi' se hai voglia puoi aiutarmi.
    Il controllo che mi serve e sulla textarea costumerSRVMOT, e qua dentro non devo fare premere invio o meglio fare in modo che se lo premo nel campo non sia presente il valore dell'invio, \n o
    ecc...
    Ciao


    <html>

    <?php

    /* Apertura connessione al database*/
    include("connection.inc");

    session_start();

    /* Se non e' presente il valore nella password e nell'utente torno alla pagina
    principale perche' non e' stata rispettata la sequenza dell'applicazione*/

    $effettuatoLOGIN = $_SESSION['effettuatoLOGIN'];

    if ($effettuatoLOGIN == "") {
    header("refresh:0 url=srvrq1.php");
    }

    ?>

    <head>
    <title>Gestione Richieste di Assistenza</title>
    <SCRIPT language="JavaScript" SRC="pnlgrp8.js"></SCRIPT>
    </head>

    <style type="text/css">

    body {
    background-attachment:"fixed";
    background-repeat:"repeat";
    cursor: Default; text-decoration: none;
    scrollbar-arrow-color: #000000;
    scrollbar-base-color: #666666;
    scrollbar-dark-shadow-color: #666666;
    scrollbar-track-color: #666666;
    scrollbar-face-color: #666666;
    scrollbar-shadow-color: #999999;
    scrollbar-highlight-color: #999999;
    scrollbar-3d-light-color: #666666;
    backgroundcolor: #666666
    }
    </style>



    <script type="text/javascript">
    function conta(val) {
    var max=462
    if (val.customerSRVMOT.value.length > max) {
    val.customerSRVMOT.value = val.customerSRVMOT.value.substring(0,max)
    }
    }
    </script>



    <script language="Javascript">
    function verificacaratteri(campo)
    {
    var chiffres = new RegExp("[a-z-A-Z-0-9,-?\/*\r\n.:;*()?!%@#§àùè+ ]");
    var verif;
    var points = 0;

    for(x = 0; x < campo.value.length; x++)
    {
    verif = chiffres.test(campo.value.charAt(x));
    if(campo.value.charAt(x) == "."){points++;}
    if(points > 1){verif = false; points = 1;}
    if(verif == false){campo.value = campo.value.substr(0,x) + campo.value.substr(x+1,campo.value.length-x+1); x--;}
    }

    }
    </script>



    <script type="text/javascript">
    window.onload = function() {
    document.getElementById('customerSRVMOT').focus();
    }
    </script>


    <script language="javascript">
    <!--
    function checkForm()
    {

    if (document.action.customerSRVPER.value==""){
    alert("Riferimento obbligatorio");
    document.action.customerSRVPER.focus();
    return false;
    }

    if (document.action.customerSRVEMA.value==""){
    alert("E-Mail obbligatoria");
    document.action.customerSRVEMA.focus();
    return false;
    }

    if (document.action.customerSRVMOT.value==""){
    alert("Motivo della chiamata obbligatorio");
    document.action.customerSRVMOT.focus();
    return false;
    }


    }
    //-->
    </script>


    <script language="javascript">
    document.action.customerSRVMOT.onkeyup = KeyCheck;
    function KeyCheck(e)
    {
    var KeyID = (window.event) ? event.keyCode : e.keyCode;
    //alert(KeyID);
    switch (KeyID)
    {
    case 10:
    case 13:
    var str = new String(document.action.customerSRVMOT.value);
    var len = str.length;
    len--;
    document.getElementById('customerSRVMOT').value=do cument.getElementById('customerSRVMOT').value.subs tr(0,len);
    break;
    }
    }
    </script>




    <?php





    /* Reperimento variabile passata dal chiamante con il metodo GET */

    $customerSERCLI = $_SESSION['customerCLSCLI'];
    $customerSERSRN = $_SESSION['customerSERSRN'];
    $customerSERMOD = $_SESSION['customerSERMOD'];
    $customerSERNSP = $_SESSION['customerSERNSP'];
    $customerSERPRO = $_SESSION['customerSERPRO'];
    $customerSERVRS = $_SESSION['customerSERVRS'];
    $customerSERBLD = $_SESSION['customerSERBLD'];
    $customerSERASP = $_SESSION['customerSERASP'];
    $customerSERREL = $_SESSION['customerSERREL'];
    $customerPRODES = $_SESSION['customerPRODES'];

    $customerSRVPER = $_GET["customerSRVPER"];
    $customerSRVEMA = $_GET["customerSRVEMA"];

    $_SESSION['customerSRVPER'] = $customerSRVPER;
    $_SESSION['customerSRVEMA'] = $customerSRVEMA;
    $_SESSION['customerSRVMOT'] = $customerSRVMOT;

    $customerSRVDAT = (date("Y-m-d"));
    $customerSRVORA = (date("H.i.s"));
    $customerSRVMOT = "";


    ?>


    <body style="overflow:hidden;" bgcolor="#F7F7F7" leftmargin="0" rightmargin="0" topmargin="0">
    <table border="0" width="100%" >
    <tr>
    <td height="50" colspan="2">
    [img]titolo.bmp[/img]</td>

    </tr>

    <tr>
    <td width="15%">
    </td>
    <td rowspan="2" valign="top" height="426" width="90%">

    <font face="Arial Black">


    Gestione Richieste di Assistenza</font>





    <?php print( date("d M Y H:i:s", time()) ); ?>



    <?php
    print '<form name="action" onsubmit="return checkForm();" action="srvrq9.php?
    customerSRVCLI=' . $customerSERCLI . '&customerSRVSRN=' . $customerSERSRN . '
    &customerSRVMOD=' . $customerSERMOD . '&customerSRVNSP=' . $customerSERNSP . '
    &customerSRVPRO=' . $customerSERPRO . '&customerSRVVER=' . $customerSERVRS . '
    &customerSRVBLD=' . $customerSERBLD . '&customerSRVREL=' . $customerSERREL . '
    &customerSRVASP=' . $customerSERASP . '&customerSRVPER=' . $customerSRVPER . '
    &customerSRVEMA=' . $customerSRVEMA . '&customerSRVMOT=' . $customerSRVMOT . '
    " method="POST">';

    print '<input type=hidden name="customerSRVCLI" value="'.$customerSERCLI.'" />';

    Print 'Server

    '.$customerSERSRN.' Model
    '.$customerSERMOD.' Partition
    '.$customerSERNSP.'
    ';

    Print 'Prodotto

    '.$customerSERPRO.' rel.
    '.$customerSERVRS.'
    '.$customerPRODES.'
    ';

    Print 'Build


    '.$customerSERBLD.'
    ';

    Print 'Service release
    '.$customerSERREL.'
    ';

    Print 'Service pack

    '.$customerSERASP.'
    ';

    print '
    ';

    print 'Riferimento

    <input type="text" size="35" maxlength="35" onkeyup=verificacaratteri(this); name="customerSRVPER" value="'.$customerSRVPER.'"/>
    ';

    print 'Indirizzo mail

    <input type="text" size="80" maxlength="80" onkeyup=verificacaratteri(this); name="customerSRVEMA" value="'.$customerSRVEMA.'"/>
    ';

    ?>
    <table border="0" width="100%">
    <tr>
    <td width="129" align="left" valign="top">Motivo</td>
    <td>
    <td>



    <?php print '<textarea id="customerSRVMOT" name="customerSRVMOT" rows="5" cols="61" onkeyup=KeyCheck(this.form); onkeyup=conta(this.form);verificacaratteri(this);> '.$customerSRVMOT.'</textarea>';



    ?>
    </tr>
    </table>

    <?php

    print '

    ';
    ?>

    </td>
    </tr>
    <tr>
    <td width="110" height="344" valign="top">

    <?php


    print '<input type="submit" name="action" value="Registra " /></form>';

    print '<form action="srvrq3.php" method="POST">';
    print '<input type="submit" name="action" value="Server " /></form>';

    print '<form action="srvrq7.php" method="POST">';
    print '<input type="submit" name="action" value="Contatti " /></form>';


    print '<form action="srvrq5.php" method="POST">';
    print '<input type="submit" name="action" value="Scelte " /></form>';

    print '<form action="srvrq4.php" name="close" method="POST">';
    print '<input type="submit" name="close" value="Chiudi " /></form>';

    print '<form action="javascript:;" method="POST">';
    print '<input type="submit" onclick="popup()" value="Aiuto " name="B1" /></form>';

    ?>
    <div ID="maildiv" style="visibility:hidden;position:absolute;
    left: 70px; width: 354px; height: 589px; top: 12px" align="center"></div>

    </td>


    </tr>
    </table>
    [img]sotto.bmp[/img]

    </body>
    </html>

  6. #6
    le modifiche che ti suggerisco sono
    document.ciccio.value=document.getElementById('cic cio').value.substr(0,len);
    al posto di
    document.getElementById('ciccio').value=document.g etElementById('ciccio').value.substr(0,len);

    e poi
    <textarea id="customerSRVMOT" name="customerSRVMOT" rows="5" cols="61" onkeyup=conta(this.form);verificacaratteri(this);> '.$customerSRVMOT.'</textarea>

    al posto di

    <textarea id="customerSRVMOT" name="customerSRVMOT" rows="5" cols="61" onkeyup=KeyCheck(this.form); onkeyup=conta(this.form);verificacaratteri(this);> '.$customerSRVMOT.'</textarea>

  7. #7
    Utente di HTML.it
    Registrato dal
    Aug 2006
    Messaggi
    833
    ho fatto come hai detto, pero' scrive il carattere dell'invio, infatti quando guardo il record
    dall'as400 il valore nel motivo non e' valido perche' c'e' il valore dell'invio, penso sia \n.

    Quello che vorrei io e' quando viene premuto l'invio, sostituirlo con un blanks, cioe' non deve essere scritto nel record il valore corrispondente all'invio.

  8. #8
    Utente di HTML.it
    Registrato dal
    Aug 2006
    Messaggi
    833
    Posto una soluzione che ho trovato, se altri avranno bisogno di questa gestione.
    Ciao e grazie

    <script language="Javascript">

    var nuovariga = /\n/g;
    function verificacaratteri(campo)

    {
    var NuovoTesto = document.getElementById("customerSRVMOT").value;
    NuovoTesto = NuovoTesto.replace(nuovariga, "");
    var DivElement = document.getElementById("customerSRVMOT");
    DivElement.innerHTML = NuovoTesto;
    }


    </script>

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.