I can't understand why the code doesn't seems to function very well

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default I can't understand why the code doesn't seems to function very well

    can you help me please because I can't understand why the code doesn't seems
    to function very well:

    in onkeypress it must verify if insert number or string value in the fiels,
    but it doesn't seems to function very well
    (in frontpage it works but here it doesn't)

    PROGRAMMA IN FRONTPAGE

    <form method="get" name="f">
    numerico<input type="text" name="t1" onkeypress="return
    numeralsOnly(event)"/><br/>

    stringa <input type="text" name="t2" onkeypress="return
    lettersOnly(event)"/><br/>



    PROGRAMMA IN PHP


    <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    <html>
    <head>
    <title>Title here!</title>
    </head>
    <body>
    <script type="text/javascript">

    function numeralsOnly(evt)
    {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ?
    evt.keyCode : ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 48 || charCode > 57))
    {
    alert("Puoi inserire solo numeri!");
    return false;
    }
    return true;
    }

    function lettersOnly(evt)
    {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ?
    evt.keyCode : ((evt.which) ? evt.which : 0));
    if (charCode > 31 && (charCode < 65 || charCode > 90) && (charCode < 97 ||
    charCode > 122))
    {
    alert("Puoi inserire solo lettere!");
    return false;
    }
    return true;
    }
    </script>

    <?php
    //--------------------------------------------------------------------------
    ----
    // INSERISCE UN CAMPO DI EDIT (CAMBIA COLORE AL SUO SFONDO QUANDO HA IL
    FOCUS)
    // InsertEditField("digita il tuo Nome","Nome","prova","60",10);
    //--------------------------------------------------------------------------
    ----
    function InsertEditField($DataType,$FieldName)
    {
    if ($DataType='integer')
    echo "<input type='TEXT' name='$FieldName' onkeypress='return
    numeralsOnly(event)'>";
    else
    if ($DataType='string')
    echo "<input type='TEXT' name='$FieldName' onkeypress='return
    lettersOnly(event)'>";
    }

    function Prova($Host,$User,$Password,$DBName,$TableName)
    {
    $Query="select * from $TableName";

    //SI CONNETTE AD UNA TABELLA IN MY SQL
    $Connessione=mysql_connect($Host,$User,$Password);

    //SELEZIONA UN DATABASE IN MY SQL
    mysql_select_db($DBName,$Connessione);

    //CREA UNA QUERY SU UNA TABELLA DI UN DATABASE IN MY SQL
    $result=mysql_query($Query);

    //ottiene l'elenco dei campi
    $campi = mysql_list_fields($DBName,$TableName,$Connessione) ;

    //ottiene il totale dei campi
    $colonne = mysql_num_fields($campi);

    //creo la form
    echo "<form>";

    for ($i=0; $i<$colonne; $i++)
    {
    $TipoCampo=mysql_field_type($campi, $i);

    if ($TipoCampo='int')
    InsertEditField("integer","Campo $i");
    else
    if ($TipoCampo='string')
    InsertEditField("string","Campo $i");
    }

    //chiudo il tag della form
    echo "<input type='submit' value='Invia'>";
    echo "<input type='reset' value='Annulla'>";
    echo "</form>";
    }

    Prova('localhost','utente','password','db','tabell a');
    ?>
    </body>
    </html>



    SAN CAZIANO Guest

  2. Similar Questions and Discussions

    1. Don't quite understand the Book function
      Hi there, I'm trying to break up an annual report into chapters and put all the documents together in a book. Have done that, but having a problem...
    2. Calling Javascript function using MM_Menu code
      Hello All, I am trying to call a javascript function in a drop-down menu create from Fireworks the old "MM_Menu" code. I want my javascript to...
    3. How To: handle DataGrid row Click Event that passes rows column values to server-side code behind function
      I've looked through many posted messages, and have tried several things but have not seemed to solve this (what you'd think would be a simple)...
    4. passing code inside function
      I would like to read something about passing code inside function. Lets say that: This works: perl -e 'sub a(&){print(&{$_}, "/n"};$_=0; a...
    5. #26061 [Opn->Csd]: mail function chops html code when is used with php ver 4.3.3
      ID: 26061 Updated by: iliaa@php.net Reported By: soporte at redycomercio dot com -Status: Open +Status: ...
  3. #2

    Default Re: I can't understand why the code doesn't seems to function ve

    "SAN CAZIANO1" wrote:
    > can you help me please because I can't understand why the code
    > doesn't seems
    > to function very well:
    >
    > in onkeypress it must verify if insert number or string value
    > in the fiels,
    > but it doesn't seems to function very well
    > (in frontpage it works but here it doesn't)
    >
    > PROGRAMMA IN FRONTPAGE
    >
    > <form method="get" name="f">
    > numerico<input type="text" name="t1" onkeypress="return
    > numeralsOnly(event)"/><br/>
    >
    > stringa <input type="text" name="t2" onkeypress="return
    > lettersOnly(event)"/><br/>
    >
    >
    >
    > PROGRAMMA IN PHP
    >
    >
    > <!doctype html public "-//W3C//DTD HTML 4.0 //EN">
    > <html>
    > <head>
    > &lt;title&gt;Title here!&lt;/title&gt;
    > </head>
    > <body>
    > <script type="text/javascript">
    >
    > function numeralsOnly(evt)
    > {
    > evt = (evt) ? evt : event;
    > var charCode = (evt.charCode) ? evt.charCode :
    > ((evt.keyCode) ?
    > evt.keyCode : ((evt.which) ? evt.which : 0));
    > if (charCode &gt; 31 && (charCode &lt; 48 || charCode &gt;
    > 57))
    > {
    > alert("Puoi inserire solo numeri!");
    > return false;
    > }
    > return true;
    > }
    >
    > function lettersOnly(evt)
    > {
    > evt = (evt) ? evt : event;
    > var charCode = (evt.charCode) ? evt.charCode :
    > ((evt.keyCode) ?
    > evt.keyCode : ((evt.which) ? evt.which : 0));
    > if (charCode &gt; 31 && (charCode &lt; 65 || charCode &gt;
    > 90) && (charCode &lt; 97 ||
    > charCode > 122))
    > {
    > alert("Puoi inserire solo lettere!");
    > return false;
    > }
    > return true;
    > }
    > </script>
    >
    > <?php
    > //------------------------------------------------------------
    > --------------
    > ----
    > // INSERISCE UN CAMPO DI EDIT (CAMBIA COLORE AL SUO
    > SFONDO QUANDO HA IL
    > FOCUS)
    > // InsertEditField("digita il tuo
    > Nome","Nome","prova","60",10);
    > //------------------------------------------------------------
    > --------------
    > ----
    > function InsertEditField($DataType,$FieldName)
    > {
    > if ($DataType='integer')
    > echo "&lt;input type='TEXT' name='$FieldName'
    > onkeypress='return
    > numeralsOnly(event)'>";
    > else
    > if ($DataType='string')
    > echo "&lt;input type='TEXT' name='$FieldName'
    > onkeypress='return
    > lettersOnly(event)'>";
    > }
    >
    > function Prova($Host,$User,$Password,$DBName,$TableName)
    > {
    > $Query="select * from $TableName";
    >
    > //SI CONNETTE AD UNA TABELLA IN MY SQL
    > $Connessione=mysql_connect($Host,$User,$Password);
    >
    > //SELEZIONA UN DATABASE IN MY SQL
    > mysql_select_db($DBName,$Connessione);
    >
    > //CREA UNA QUERY SU UNA TABELLA DI UN DATABASE IN MY SQL
    > $result=mysql_query($Query);
    >
    > //ottiene l'elenco dei campi
    > $campi = mysql_list_fields($DBName,$TableName,$Connessione) ;
    >
    > //ottiene il totale dei campi
    > $colonne = mysql_num_fields($campi);
    >
    > //creo la form
    > echo "&lt;form&gt;";
    >
    > for ($i=0; $i&lt;$colonne; $i++)
    > {
    > $TipoCampo=mysql_field_type($campi, $i);
    >
    > if ($TipoCampo='int')
    > InsertEditField("integer","Campo $i");
    > else
    > if ($TipoCampo='string')
    > InsertEditField("string","Campo $i");
    > }
    >
    > //chiudo il tag della form
    > echo "&lt;input type='submit' value='Invia'&gt;";
    > echo "&lt;input type='reset' value='Annulla'&gt;";
    > echo "&lt;/form&gt;";
    > }
    >
    > Prova('localhost','utente','password','db','tabell a');
    > ?>
    > </body>
    > </html>
    Suggest you put it through a PHP debugger. There are many free and
    paid debuggers. I used zend (paid, but very nice).

    --
    [url]http://www.dbForumz.com/[/url] This article was posted by author's request
    Articles individually checked for conformance to usenet standards
    Topic URL: [url]http://www.dbForumz.com/PHP-understand-code-function-ftopict157032.html[/url]
    Visit Topic URL to contact author (reg. req'd). Report abuse: [url]http://www.dbForumz.com/eform.php?p=526229[/url]
    steve Guest

  4. #3

    Default Re: I can't understand why the code doesn't seems to function verywell

    SAN CAZIANO wrote:
    > can you help me please because I can't understand why the code doesn't seems
    > to function very well:
    >
    > in onkeypress it must verify if insert number or string value in the fiels,
    > but it doesn't seems to function very well
    > (in frontpage it works but here it doesn't)
    >
    > PROGRAMMA IN FRONTPAGE
    >
    > <form method="get" name="f">
    > numerico<input type="text" name="t1" onkeypress="return
    > numeralsOnly(event)"/><br/>
    >
    > stringa <input type="text" name="t2" onkeypress="return
    > lettersOnly(event)"/><br/>
    You seem to be confusing Javascript and PHP -
    Javascript is *client*-side while PHP is *server*-side.

    Assuming that PROGRAMMA IN FRONTPAGE and PROGRAMMA IN PHP are seperate
    files, your PHP program will not be aware of any data until the form is
    submitted to the server, therefore your validation needs to be done in
    the browser.

    Regards,

    Andy
    Andy Barfield Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139