Ask a Question related to PHP Development, Design and Development.
-
SAN CAZIANO #1
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
-
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... -
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... -
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)... -
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... -
#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: ... -
steve #2
Re: I can't understand why the code doesn't seems to function ve
"SAN CAZIANO1" wrote:
Suggest you put it through a PHP debugger. There are many free and> 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>
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
-
Andy Barfield #3
Re: I can't understand why the code doesn't seems to function verywell
SAN CAZIANO wrote:
You seem to be confusing Javascript and PHP -> 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/>
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



Reply With Quote

