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

    Controlli javascript in un form

    Premetto che sono neofita sia del sito che di siti web...Vi chiedo aiuto perche' all'interno del form di cui vi invio il codice ho bisogno oltre ai controlli js che ho gia' inserito di un controllo che faccia inserire solo lettere nel campo name e surname e non so come fare .....poi vorrei fare in modo che i campi telefono e email(caselle di testo) si attivano solo quando sono cheked i due ceckbox corrispondenti e inoltre ho inserito una limitazioni di caratteri nella textarea tramite js,ma su explorer funziona su firefox no..Vi prego di rispondermi il prima possibile sto impazzendo Ringrazio in anticipio chi e' cosi gentile da aiutarmi
    <script language="javascript">
    <!--
    function Modulo() {
    //Var
    var name = document.modulo.name.value;
    var surname = document.modulo.surname.value;
    var message = document.modulo.message.value;
    var email = document.modulo.email.value;
    var tel = document.modulo.tel.value;
    //email
    var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
    //control name
    if ((name == "") || (name == "undefined")) {
    alert("Name is mandatory");
    document.modulo.name.focus();
    return false;
    }
    //control surname
    else if ((surname == "") || (surname == "undefined")) {
    alert("Surname is mandatory");
    document.modulo.surname.focus();
    return false;
    }
    //Control
    else if((message == "") || (message == "undefined")) {
    alert("Please leave a message");
    document.modulo.message.focus();
    return false;
    }
    //control tel
    else if ((tel != "") && ((isNaN(tel))|| (tel == "undefined"))) {
    alert("Please enter numbers ONLY");
    document.modulo.tel.value = "";
    document.modulo.tel.focus();
    return false;
    }
    else if((email != "") && (!email_reg_exp.test(email) || (email == "undefined"))) {
    alert("Please enter a valid email address");
    document.modulo.email.select();
    return false;
    }

    else if((email == "") && (tel == "")) {
    alert("Please enter a contact email or telephone number");
    document.modulo.email.select();
    return false;
    }
    //invia modulo
    else {

    document.modulo.submit();
    }
    }
    //-->
    </script>
    <script type="text/javascript">

    /*
    Form field Limiter script
    */

    var ns6=document.getElementById&&!document.all

    function restrictinput(maxlength,e,placeholder){
    if (window.event&&event.srcElement.value.length>=maxl ength)
    return false
    else if (e.target&&e.target==eval(placeholder)&&e.target.v alue.length>=maxlength){
    var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
    if (pressedkey.test(String.fromCharCode(e.which)))
    e.stopPropagation()
    }
    }

    function countlimit(maxlength,e,placeholder){
    var theform=eval(placeholder)
    var lengthleft=maxlength-theform.value.length
    var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
    if (window.event||e.target&&e.target==eval(placeholde r)){
    if (lengthleft<0)
    theform.value=theform.value.substring(0,maxlength)
    placeholderobj.innerHTML=lengthleft
    }
    }


    function displaylimit(thename, theid, thelimit){
    var theform=theid!=""? document.getElementById(theid) : thename
    var limit_text='You can insert just <span id="'+theform.toString()+'">'+thelimit+'</span> characters'
    if (document.all||ns6)
    document.write(limit_text)
    if (document.all){
    eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
    eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
    }
    else if (ns6){
    document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
    document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
    }
    }
    </script>

    <style type="text/css">
    <!--
    table {
    font-family: "Comic Sans MS", "Times New Roman";
    font-size: 12pt;
    text-align: justify;
    border: 6px ;
    }
    -->
    </style>
    </head>

    <body background="img/sfondo.gif" onLoad="MM_preloadImages('img/homedown.gif','img/servicesdown.gif','img/contactdown.gif','img/rfdown.gif','img/feedbackdown.gif')">
    <div align="center" id="banner">
    <table width="764" height="136" cellpadding="0" cellspacing="0" bgcolor="#51c251" bordercolor="#51c251">
    <tr>
    <td> [img]img/banner.gif[/img]</td>
    </tr>
    </table>
    </div>
    <div align="center" id="bottons">
    <table cellpadding="0" cellspacing="0" width="764" border="0" bgcolor="#51c251" bordercolor="#51c251">
    <tr>
    <td>[img]img/homeup.gif[/img]</td>
    <td>[img]img/servicesup.gif[/img]</td>
    <td>[img]img/contactup.gif[/img]</td>
    <td>[img]img/rfup.gif[/img]</td>
    <td>[img]img/feedbackup.gif[/img]</td>
    </tr>
    </table>
    </div>
    <div align="center" id="form">
    <form action="mailto:a4waste@blueyonder.co.uk" method="post" enctype="text/plain" name="modulo" >


    <table cellpadding="0" cellspacing="0" width="764" border="0" bgcolor="#51c251" bordercolor="#51c251">
    <tr>
    <td>
    SUBJECT
    <select name="subject">
    <option>--------------------------------</option>
    <option>General Enquiry</option>
    <option>Request Information</option>
    <option>Request Quotation</option>
    <option>Place a order</option>
    <option>Availability</option>
    <option>Other</option>
    </select>
    </td>
    <td>
    YOUR INFORMATION Required fields *



    </td>
    </tr>
    <tr>
    <td>
    YOUR MESSAGE


    <textarea name="message" cols=30 rows=17 id="message" ></textarea>


    <script>
    displaylimit("","message",510)
    </script>
    </td>
    <td valign="top">
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
    <td>
    Title
    <select name="title">
    <option>Mr</option>
    <option>Mirs</option>
    <option>Miss</option>
    <option>Ms</option>
    </select>
    </td>
    </tr>
    <tr>
    <td>


    First name
    <input name="name" type="text" id="name" value="" maxlength="20" onKeyUp="OnlyLetters(name)">*
    </td>
    </tr>
    <tr>
    <td>
    Surname
    <input name="surname" type="text" maxlength="20">*
    </td>
    </tr>
    <tr>
    <td>


    REPLY PREFERENCE


    <input name="cemail" type="checkbox">
    E-mail

    <input name="email" type="text" maxlength="50" >
    </td>
    </tr>
    <tr>
    <td>
    <input name="ctel" type="checkbox" value="">
    Telephone

    <input name="tel" type="text" value="" maxlength="20" >




    <input name="anytime" type="checkbox" value="" >
    Any time




    <input name="office" type="checkbox" value="" >
    Office hours




    <input name="evenings" type="checkbox" value="">
    Evenings




    <input name="weekends" type="checkbox" value="">
    Weekends
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td align="center">
    <input name="bsub" type="submit" value="Send" onClick="Modulo()">
    </td>
    <td align="center">
    <input name="bcan" type="reset" value="Cancel">
    </td>
    </tr>
    </table>
    </form>
    </div>
    </body>

  2. #2

    ma nessuno risponde ??

  3. #3
    :master:
    Ho risolto in parte i miei problemi...Qualcuno mi puo' controllare il codice perche' ci sono ancora degli errori chr non riesco a capire..Grazie

    <html>
    <head>
    <script language="javascript">
    <!--
    function Modulo() {
    //Var
    var name = document.modulo.name.value;
    var surname = document.modulo.surname.value;
    var message = document.modulo.message.value;
    var email = document.modulo.email.value;
    var tel = document.modulo.tel.value;
    //email
    var email_reg_exp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

    //NAME + SURNAME CHECK
    var char_exp = /[A-Za-z\.\,\/]/;
    send=true;

    //control name
    if ((name == "") || (name == "undefined")) {
    alert("Name is mandatory");
    document.modulo.name.focus();
    send=false;
    return=send;
    }

    // CONTROL LENGHT OF NAME
    if ((name.length <= 4) ||(name.length >= 20) && (!char_exp.test(name))) //CHANGE TO YOUR VALUES HERE !!
    {
    alert ("Please enter a Name using Characters only,\n\n 5 to max 20 charaters long","");
    document.modulo.name.focus();
    send=false;
    return=send;
    }
    //control surname
    if ((surname == "") || (surname == "undefined")) {
    alert("Surname is mandatory");
    document.modulo.surname.focus();
    send=false;
    return=send;
    }

    // CONTROL LENGHT OF SURNAME
    if ((surname.length <= 4) ||(surname.length >= 20) && (!char_exp.test(surname))) //CHANGE TO YOUR VALUES HERE !!
    {
    alert ("Please enter a Surame using Characters only,\n\n 5 to max 20 charaters long","");
    document.modulo.surname.focus();
    send=false;
    return=send;
    }

    //Control
    if((message == "") || (message == "undefined")) {
    alert("Please leave a message");
    document.modulo.message.focus();
    send=false;
    return=send;
    }
    //control tel
    if ((tel != "") && ((isNaN(tel))|| (tel == "undefined"))) {
    alert("Please enter numbers ONLY");
    document.modulo.tel.value = "";
    document.modulo.tel.focus();
    send=false;
    return=send;
    }
    if((email != "") && (!email_reg_exp.test(email) || (email == "undefined"))) {
    alert("Please enter a valid email address");
    document.modulo.email.select();
    send=false;
    return=send;
    }

    if((email == "") && (tel == "")) {
    alert("Please enter a contact email or telephone number");
    document.modulo.email.select();
    send=false;
    return=send;
    }
    //invia modulo
    //else {

    //document.modulo.submit();
    //}
    //}
    //-->




    </script>
    <script type="text/javascript">

    /*
    Form field Limiter script
    */

    var ns6=document.getElementById&&!document.all

    function restrictinput(maxlength,e,placeholder){
    if (window.event&&event.srcElement.value.length>=maxl ength)
    return false
    else if (e.target&&e.target==eval(placeholder)&&e.target.v alue.length>=maxlength){
    var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
    if (pressedkey.test(String.fromCharCode(e.which)))
    e.stopPropagation()
    }
    }

    function countlimit(maxlength,e,placeholder){
    var theform=eval(placeholder)
    var lengthleft=maxlength-theform.value.length
    var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
    if (window.event||e.target&&e.target==eval(placeholde r)){
    if (lengthleft<0)
    theform.value=theform.value.substring(0,maxlength)
    placeholderobj.innerHTML=lengthleft
    }
    }


    function displaylimit(thename, theid, thelimit){
    var theform=theid!=""? document.getElementById(theid) : thename
    var limit_text='You can insert just <span id="'+theform.toString()+'">'+thelimit+'</span> characters'
    if (document.all||ns6)
    document.write(limit_text)
    if (document.all){
    eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
    eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
    }
    else if (ns6){
    document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true);
    document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true);
    }
    }
    </script>

    <style type="text/css">
    <!--
    table {
    font-family: "Comic Sans MS", "Times New Roman";
    font-size: 12pt;
    text-align: justify;
    border: 6px ;
    }
    -->
    </style>
    </head>

    <body background="img/sfondo.gif" onLoad="MM_preloadImages('img/homedown.gif','img/servicesdown.gif','img/contactdown.gif','img/rfdown.gif','img/feedbackdown.gif')">
    <div align="center" id="banner">
    <table width="764" height="136" cellpadding="0" cellspacing="0" bgcolor="#51c251" bordercolor="#51c251">
    <tr>

    <td> [img]img/banner.gif[/img]</td>

    </tr>
    </table>
    </div>
    <div align="center" id="bottons">
    <table cellpadding="0" cellspacing="0" width="764" border="0" bgcolor="#51c251" bordercolor="#51c251">
    <tr>
    <td>[img]img/homeup.gif[/img]</td>
    <td>[img]img/servicesup.gif[/img]</td>

    <td>[img]img/contactup.gif[/img]</td>
    <td>[img]img/rfup.gif[/img]</td>

    <td>[img]img/feedbackup.gif[/img]</td>
    </tr>
    </table>
    </div>
    <div align="center" id="form">
    <form action="mailto:a4waste@blueyonder.co.uk" method="post" enctype="text/plain" name="modulo" onSubmit="return Modulo()" >


    <table cellpadding="0" cellspacing="0" width="764" border="0" bgcolor="#51c251" bordercolor="#51c251">

    <tr>
    <td>

    SUBJECT
    <select name="subject">
    <option>--------------------------------</option>
    <option>General Enquiry</option>
    <option>Request Information</option>

    <option>Request Quotation</option>
    <option>Place a order</option>

    <option>Availability</option>
    <option>Other</option>
    </select>
    </td>

    <td>
    YOUR INFORMATION Required fields *




    </td>
    </tr>
    <tr>
    <td>
    YOUR MESSAGE



    <blockquote>
    <textarea name="message" cols=30 rows=17 id="message" wrap="physical"></textarea>
    </blockquote>



    <script>
    displaylimit("","message",510)
    </script>
    </td>
    <td valign="top">

    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
    <td>
    Title

    <select name="title">
    <option>Mr</option>
    <option>Mirs</option>

    <option>Miss</option>
    <option>Ms</option>
    </select>
    </td>

    </tr>
    <tr>
    <td>



    First name
    <input name="name" type="text" id="name" value="" maxlength="20">*
    </td>
    </tr>
    <tr>
    <td>

    Surname
    <input name="surname" type="text" id="surname" value="" maxlength="20">*
    </td>

    </tr>
    <tr>
    <td>


    REPLY PREFERENCE



    <input name="cemail" type="checkbox">
    E-mail


    <input name="email" type="text" maxlength="50" >
    </td>
    </tr>
    <tr>
    <td>
    <input name="ctel" type="checkbox" value="">

    Telephone

    <input name="tel" type="text" value="" maxlength="20" >





    <input name="anytime" type="checkbox" value="" >
    Any time





    <input name="office" type="checkbox" value="" >

    Office hours




    <input name="evenings" type="checkbox" value="">
    Evenings






    <input name="weekends" type="checkbox" value="">
    Weekends
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>

    <td align="center">

    <input name="bsub" type="submit" value="Send" onClick="Modulo()">
    </td>
    <td align="center">
    <input name="bcan" type="reset" value="Cancel">
    </td>
    </tr>
    </table>
    </form>

    </div>
    </body>

    </html> :master:

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 © 2026 vBulletin Solutions, Inc. All rights reserved.