By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,543 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,543 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>

Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"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).

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-understa...ict157032.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=526229
Jul 17 '05 #2

P: n/a
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
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.