473,666 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.i ndexOf(c) == -1)
return false;
}
// All characters are whitespace.
return true;
}
//
//
function validate()
{
if(isEmpty(docu ment.online_reg istration_form_ calc.names.valu e))
{
alert('Entry in "Name\(s\)" field required.');
document.online _registration_f orm_calc.names. focus();
return false;
}
return true;
}
<?php
print("<input name=\"names\" type=\"text\" id=\"names\" value=\"".$_REQ UEST['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 1715
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.i ndexOf(c) == -1)
return false;
}
// All characters are whitespace.
return true;
}
//
//
function validate()
{
if(isEmpty(docu ment.online_reg istration_form_ calc.names.valu e))
{
alert('Entry in "Name\(s\)" field required.');
document.online _registration_f orm_calc.names. focus();
return false;
}
return true;
}
<?php
print("<input name=\"names\" type=\"text\" id=\"names\" value=\"".$_REQ UEST['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
2463
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 has a " in it"...> I tried preceeding the " with a the escape char \, but the browser apparently still used the embedded " as termination of the value string. One other thing...is the delimiter limited to just " and ' ?
3
2588
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" onblur=document.cookie="user=" + box1.value> Chris
2
5960
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 I get rid of that? If the old <INPUT> button has been deprecated in favor of <BUTTON>, have all it's button functions been duplicated? Thanks for any help,
3
13142
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 this, with a flush left margin:
2
1269
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. <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,...
3
12917
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 type=submit value='Done'> </form>
2
5314
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: ================ // ==UserScript== // @name AddInput
4
18430
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 advance, Rick
2
3281
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 itself, where it checks the values that were entered. If the default values are set, this is the visitor's first time to access the page. Example: The FirstName field would initially be displayed with "First Name;"
0
8445
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8356
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8781
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8551
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7386
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5664
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2011
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.