473,385 Members | 1,546 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,385 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 23 '05 #1
2 1254
Don
On Thu, 03 Feb 2005 07:23:21 -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 23 '05 #2
JRS: In article <0u********************************@4ax.com>, dated
Thu, 3 Feb 2005 07:23:21, seen in news:comp.lang.javascript, Don
<no@adr.com> posted :
// 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;
}


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.
Jul 23 '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...
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: 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...
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: Richard Maher | last post by:
Hi, I'm trying to use the Visibility Style attribute for a Div to effectively PopUp a lightweight window with some additional context-sensitive information, when a user mouses over a given...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.