473,503 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>

Jul 17 '05 #1
2 2498
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

39
6477
by: Randell D. | last post by:
Folks, I'm sure this can be done legally, and not thru tricks of the trade - I hope someone can help. I'm writing a 'tool' (a function) which can be used generically in any of my projects. ...
14
2485
by: Robin Tucker | last post by:
Although I've been working on this project for 8 months now, I'm still not sure of the difference between ByVal and ByRef. As most objects in VB are reference types, passing ByVal I've discovered...
88
7953
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
24
2957
by: Randall Arnold | last post by:
I know how to use MSHTML to grab the innerhtml from an html web page, but what if I want to look at elements of a rendered aspx page? Is there any way to do this using the MSHTML DOM object? ...
73
4536
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
20
3560
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
6
4841
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
26
3022
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
37
3893
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7468
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.