Connecting Tech Pros Worldwide Help | Site Map

Test on <input> value fails

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 05:33 PM
Don
Guest
 
Posts: n/a
Default Test on <input> value fails

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 =----

  #2  
Old July 23rd, 2005, 05:33 PM
Don
Guest
 
Posts: n/a
Default Re: Test on <input> value fails

On Thu, 03 Feb 2005 07:23:21 -0700, Don <no@adr.com> wrote:
[color=blue]
>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 =----[/color]
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 =----
  #3  
Old July 23rd, 2005, 05:34 PM
Dr John Stockton
Guest
 
Posts: n/a
Default Re: Test on <input> value fails

JRS: In article <0ub401dg7eahpvskf3eci4a9u7llb4q946@4ax.com>, dated
Thu, 3 Feb 2005 07:23:21, seen in news:comp.lang.javascript, Don
<no@adr.com> posted :
[color=blue]
>// 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;
> }[/color]

That looks rather like

function isEmpty(s) { return !/\S/.test(s) }

but perhaps you are paid by the yard of code?

<URL:http://www.merlyn.demon.co.uk/js-valid.htm>

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.