473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Test on <input> value fails

Don
Can't figure this one out. The "validate" function below checks to make sure the field "names" is
not null. "validate" actually calls "isEmpty", which scans the field.

Here's the situation. <input> for "names" first existed in an html file. The test worked just fine
there. If the field was filled, the test would pass. If the field was cleared after having been
filled, it would fail as it should.

The field is then passed, via POST, to a PHP script, where it is checked for non-null in the same
manner using the code below. The same field content appears when the page is returned to the
client. The only thing is if I clear the field, the JavaScrpt function "validate" thinks the field
is still non-null, and the test passes when it should have failed. Any idea what's going on here?

Thanks for your help,
Don
//
// Define whitespace characters
var whitespace = " \t\n\r";
function isEmpty(s)
{
var i;
if((s==null) || (s.length == 0))
return true;
// Search string looking for characters that are not whitespace
for(i=0; i <s.length; i++)
{
var c = s.charAt(i);
if(whitespace.indexOf(c) == -1)
return false;
}
// All characters are whitespace.
return true;
}
//
//
function validate()
{
if(isEmpty(document.online_registration_form_calc. names.value))
{
alert('Entry in "Name\(s\)" field required.');
document.online_registration_form_calc.names.focus ();
return false;
}
return true;
}
<?php
print("<input name=\"names\" type=\"text\" id=\"names\" value=\"".$_REQUEST['names']."\"
size=\"97\">\n");
?>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #1
2 1702
Don
On Thu, 03 Feb 2005 08:07:10 -0700, Don <no@adr.com> wrote:
Can't figure this one out. The "validate" function below checks to make sure the field "names" is
not null. "validate" actually calls "isEmpty", which scans the field.

Here's the situation. <input> for "names" first existed in an html file. The test worked just fine
there. If the field was filled, the test would pass. If the field was cleared after having been
filled, it would fail as it should.

The field is then passed, via POST, to a PHP script, where it is checked for non-null in the same
manner using the code below. The same field content appears when the page is returned to the
client. The only thing is if I clear the field, the JavaScrpt function "validate" thinks the field
is still non-null, and the test passes when it should have failed. Any idea what's going on here?

Thanks for your help,
Don
//
// Define whitespace characters
var whitespace = " \t\n\r";
function isEmpty(s)
{
var i;
if((s==null) || (s.length == 0))
return true;
// Search string looking for characters that are not whitespace
for(i=0; i <s.length; i++)
{
var c = s.charAt(i);
if(whitespace.indexOf(c) == -1)
return false;
}
// All characters are whitespace.
return true;
}
//
//
function validate()
{
if(isEmpty(document.online_registration_form_calc. names.value))
{
alert('Entry in "Name\(s\)" field required.');
document.online_registration_form_calc.names.focus ();
return false;
}
return true;
}
<?php
print("<input name=\"names\" type=\"text\" id=\"names\" value=\"".$_REQUEST['names']."\"
size=\"97\">\n");
?>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----

Never mind. I found my problem. Can't believe I did this. Wasn't using the correct <form> name on
the second validation pass.

Thanks anyway.
Don

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Jul 17 '05 #2
*** Don escribió/wrote (Thu, 03 Feb 2005 13:10:04 -0700):
Never mind. I found my problem. Can't believe I did this. Wasn't using
the correct <form> name on the second validation pass.


Glad to hear that.

BTW, JavaScripts supports regular expressions. You can probably replace
your 14-line functions with one-liners similar to:

return text.replace(/\s+)/g, '')==''; // Not tested
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox
--
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Don | last post by:
Using PHP, I'm creating an <input> tag. How do you delimit the text string for the value parm of an <input> tag, when the string contains the delimit char? Example: <input...value="This text...
3
by: chirs | last post by:
Hi, I want to put a value in a cookie. The following code does not work. It does not store the box1.value in the cookie. How can I fix it? <input type="text" name="box1"...
2
by: not 2 swift | last post by:
I thought I would update an old page on which I had used a <INPUT TYPE=image ...> with a <BUTTON><IMG SRC=...></BUTTON> The problem is that <BUTTON> always provides a shadow/emboss effect. Can...
3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
2
by: Don | last post by:
Can't figure this one out. The "validate" function below checks to make sure the field "names" is not null. "validate" actually calls "isEmpty", which scans the field. Here's the situation. ...
3
by: Ben | last post by:
Here's my form: <form name="aForm" method='post'> <input type=file name=file1 onkeypress='KeyPress()'><br> <a id='attachMoreLink' href='javascript:AddFileInput()">Attach More Files </a> <input...
2
by: Mara Guida | last post by:
Hi, After I've populated a page with some <INPUT ...> elements I'd like to have access to whatever is written there. The best I've done (which does not work) is: ================ //...
4
by: Rick | last post by:
I'm trying to make an input tag visible or hidden based on the value of another input tag, so that when the 1st input tag is changed in anyway, the 2nd input tag will become visible. Thanks in...
2
by: jp2code | last post by:
I have several input fields on my form, and the form works; however, Visual Studio is showing errors, and I would like to get rid of them. When the form is submitted, it is redirected back to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...

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.