473,748 Members | 4,697 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

"return false" gives a blank page with the word "false" ?

Hello Gurus:

I have a validation script (below) that is somehow messed up. If the
Name field is blank, I get the alert message, then the browser window
goes to a blank document with the word "false" on it. What the ?!?!?!

To test, I commented out the 'return false;' code in the second IF
block, so now if there is a value in Name then I get the alert message
for Email and the page stays put.

What the heck is going on here, and am I doing wrong? BTW, the
"submit" button is a graphic.
<********** START CODE **********>
<script language="JavaS cript" type="text/javascript">
<!--
function validate() {
var x = "0";

if (document.subin fo.Name.value == "") {
alert("You must enter your First Name.");
document.subinf o.Name.focus();
x.value = "1";
return(false); }

if (document.subin fo.Email.value == "" ||
document.subinf o.Email.value.i ndexOf("@") == -1 ||
document.subinf o.Email.value.i ndexOf(".") == -1) {
alert("Invalid email address. Please re-enter it.");
document.subinf o.Email.focus() ;
// return false; }
x.value = "1"; }

if (x.value == "0") {
launchwin('than ks.html','confi rmation','heigh t=200,width=280 ');
document.subinf o.submit();
location.href = "default.ht ml"; }
}
-->
</script>

<form action="mailto: my*****@mycompa ny.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />
<input name="Company" size="24" /><br /><br />
<input name="Email" size="24" /><br /><br />
<textarea name="Comments" cols="38" rows="5"></textarea><br /><br />
<a href="javascrip t:validate()">
<img src="gfx/send.gif" name="send" width="42" height="18"
alt="Send Form" />
</a>&nbsp;&nbsp;
<a href="javascrip t:document.inqu iries.reset()">
<img src="gfx/clear.gif" name="clear" width="42" height="18"
alt="Clear Form" />
</a>
</form>

<********** END CODE **********>

Thanks,
Kurt

Feb 14 '06 #1
13 4007
wrote on 15 feb 2006 in comp.lang.javas cript:
Hello Gurus:

I have a validation script (below) that is somehow messed up. If the
Name field is blank, I get the alert message, then the browser window
goes to a blank document with the word "false" on it. What the ?!?!?!

To test, I commented out the 'return false;' code in the second IF
block, so now if there is a value in Name then I get the alert message
for Email and the page stays put.

What the heck is going on here, and am I doing wrong? BTW, the
"submit" button is a graphic.
<********** START CODE **********>
<script language="JavaS cript" type="text/javascript">
do not use language="JavaS cript"
<!--
do not use <!--
function validate() {
var x = "0";

if (document.subin fo.Name.value == "") {
alert("You must enter your First Name.");
document.subinf o.Name.focus();
x.value = "1";
return(false); }
should be:

return false; }

but then the x.value = "1"; would not be usefull,
so delete the return false here


if (document.subin fo.Email.value == "" ||
document.subinf o.Email.value.i ndexOf("@") == -1 ||
document.subinf o.Email.value.i ndexOf(".") == -1) {
alert("Invalid email address. Please re-enter it.");
document.subinf o.Email.focus() ;
// return false; }
well done //
x.value = "1"; }

if (x.value == "0") {
launchwin('than ks.html','confi rmation','heigh t=200,width=280 ');
what is launchwin() ???????????
document.subinf o.submit();
location.href = "default.ht ml"; } }
-->
</script>

<form action="mailto: my*****@mycompa ny.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />
do not use <br /> but <br>
<input name="Company" size="24" /><br /><br />
<input name="Email" size="24" /><br /><br />
<textarea name="Comments" cols="38" rows="5"></textarea><br /><br />
<a href="javascrip t:validate()">
<img src="gfx/send.gif" name="send" width="42" height="18"
alt="Send Form" />
</a>&nbsp;&nbsp;
href="javascrip t: is a bad idea, better do:

<form onsubmit='valid ate()' ...

and

<input src="gfx/send.gif" type='image' alt="Send Form">

<a href="javascrip t:document.inqu iries.reset()">
<img src="gfx/clear.gif" name="clear" width="42" height="18"
alt="Clear Form" />
</a>
same here:

<img onclick='docume nt.inquiries.re set()' src="gfx/clear.gif"
style='cursor:p ointer;'>
</form>

<********** END CODE **********>

Thanks,
Kurt


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 15 '06 #2
Hello

1. Better make use of ONSUBMIT event

2. If you are just to fix what you wrote, simply add: void(0) after your
validate function call, just like in:

<script>
function fnc1()
{
if (/*validation ok*/)
{
// submit the form
FORM_VAR.submit ();
return true;
}
return false;
}
</script>
</head>

<body>
<a href="javascrip t: fnc1();void(0); ">adsasd</a>
</body>
</html>

HTH
Elias

<ku***@ev1.ne t> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hello Gurus:

I have a validation script (below) that is somehow messed up. If the
Name field is blank, I get the alert message, then the browser window
goes to a blank document with the word "false" on it. What the ?!?!?!

To test, I commented out the 'return false;' code in the second IF
block, so now if there is a value in Name then I get the alert message
for Email and the page stays put.

What the heck is going on here, and am I doing wrong? BTW, the
"submit" button is a graphic.
<********** START CODE **********>
<script language="JavaS cript" type="text/javascript">
<!--
function validate() {
var x = "0";

if (document.subin fo.Name.value == "") {
alert("You must enter your First Name.");
document.subinf o.Name.focus();
x.value = "1";
return(false); }

if (document.subin fo.Email.value == "" ||
document.subinf o.Email.value.i ndexOf("@") == -1 ||
document.subinf o.Email.value.i ndexOf(".") == -1) {
alert("Invalid email address. Please re-enter it.");
document.subinf o.Email.focus() ;
// return false; }
x.value = "1"; }

if (x.value == "0") {
launchwin('than ks.html','confi rmation','heigh t=200,width=280 ');
document.subinf o.submit();
location.href = "default.ht ml"; }
}
-->
</script>

<form action="mailto: my*****@mycompa ny.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />
<input name="Company" size="24" /><br /><br />
<input name="Email" size="24" /><br /><br />
<textarea name="Comments" cols="38" rows="5"></textarea><br /><br />
<a href="javascrip t:validate()">
<img src="gfx/send.gif" name="send" width="42" height="18"
alt="Send Form" />
</a>&nbsp;&nbsp;
<a href="javascrip t:document.inqu iries.reset()">
<img src="gfx/clear.gif" name="clear" width="42" height="18"
alt="Clear Form" />
</a>
</form>

<********** END CODE **********>

Thanks,
Kurt

Feb 15 '06 #3
Evertjan. wrote:
<form action="mailto: my*****@mycompa ny.com" id="subinfo" method="post"
name="subinfo " enctype="text/plain">
<input name="Name" size="24" /><br /><br />

do not use <br /> but <br>

He might be using XHTML.

--
Ian Collins.
Feb 15 '06 #4
Ian Collins said the following on 2/14/2006 7:57 PM:
Evertjan. wrote:
<form action="mailto: my*****@mycompa ny.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />

do not use <br /> but <br>

He might be using XHTML.


Giving XHTML to IE is a recipe for disaster.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Feb 15 '06 #5
Randy Webb wrote:
Ian Collins said the following on 2/14/2006 7:57 PM:
Evertjan. wrote:
<form action="mailto: my*****@mycompa ny.com" id="subinfo" method="post"
name="subinfo" enctype="text/plain">
<input name="Name" size="24" /><br /><br />

do not use <br /> but <br>

He might be using XHTML.


Giving XHTML to IE is a recipe for disaster.

There's plenty out there and <br /> is the correct compatibility option.

--
Ian Collins.
Feb 15 '06 #6
Thank you all for your help. I removed the <a> tags surrounding the
<img> buttons in the form, and put the "href" code into an "onclick"
event within the <img> tag (thank you Evertjan!) Also removed the "x"
variable lines since they were redundant.

I have a question about Evertjan's response:
<script language="JavaS cript" type="text/javascript">

do not use language="JavaS cript"

<!--

do not use <!--


Why should I not use language="JavaS cript" or <!-- ??
Many thanks again!
Kurt

PS: I am using XHTML which requires self-closing empty tags (<br />).
I tested the page in various browsers (IE6, FF1.5, N6, N8, Opera8.51),
and only Netscape 6 showed a discrepancy by adding additional space
underneath various images (assumed).

Feb 15 '06 #7
Kurt wrote:
Thank you all for your help. I removed the <a> tags surrounding the
<img> buttons in the form, and put the "href" code into an "onclick"
event within the <img> tag (thank you Evertjan!) Also removed the "x"
variable lines since they were redundant.

I have a question about Evertjan's response:
<script language="JavaS cript" type="text/javascript">


do not use language="JavaS cript"


<!--


do not use <!--

Why should I not use language="JavaS cript" or <!-- ??

language="JavaS cript" isn't a valid script attribute in HTML 4 or XHTML,
try a validator on your page.

--
Ian Collins.
Feb 15 '06 #8
Ian Collins wrote on 16 feb 2006 in comp.lang.javas cript:
Kurt wrote:
do not use language="JavaS cript"

<!--
do not use <!--

Why should I not use language="JavaS cript" or <!-- ??

language="JavaS cript" isn't a valid script attribute in HTML 4 or XHTML,
try a validator on your page.


Indeed.

While it entirely possible to insert:

// this line serves no intended purpose

every other line in a js, it would only cloud the appearance of the js,
and do not good whatsoever. The same goes for the above two.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 16 '06 #9
According to validator.w3.or g, the web page (and the entire site)
passes validation for Doctype XHTML 1.0 Transitional.

I was about to argue, since it's found just about EVERYWHERE, that the
language attribute is needed, but thanks to you I found out that it is
indeed deprecated. I will stop using it in the future. However, W3C
still says to comment out code for non-script-aware browsers (see
http://www.w3.org/TR/html401/interac...dx-user_agent).

Many thanks for the lessons learned.

Kurt

Feb 16 '06 #10

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

Similar topics

3
4540
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the 'Save as Incomplete' button is Clicked the form will be going to the "SaveAsincomplete.asp" without validation of the fields. And when the 'save as complete' is clicked certain fileds are to be validated and by the function return value, if false...
1
3946
by: ItsMillerTime4u | last post by:
I'm trying to change the <body> 's event oncontextmenu attributes, but am having no luck at it. I know I can do <body oncontextmenu="contextMenu(); return false;"> but the thing is that I set's this attribute as soon as the page loads......which I don't to happen....I don't want to the context menu visible until the page is done loading, and within the window onLoad event I have a vbscript subroutine that connects to a database to pull...
11
43968
by: me | last post by:
I have got all my pages to comply with the W3C validator, except this one line as below. I need to keep the line (or the functionalilty) but it would be nice to implement it in a way that gives me a 100% pass with W3C. Any ideas? Thanks.
4
18733
by: Bradley Plett | last post by:
I have what should be a trivial problem. I am using XMLSerializer to serialize an object. It serializes boolean values as "True" and "False". I then want to use an XSLT on this XML, and I want to use one of these booleans in a test. How do I convert one of these to a boolean in a test?!? I know that I could compare it as a string to "True" or "False", but that seems extremely crude to me. The "boolean()" function (which, to me, seems...
40
3148
by: Mark P | last post by:
I'm implementing an algorithm and the computational flow is a somewhat deep. That is, fcn A makes many calls to fcn B which makes many calls to fcn C, and so on. The return value of the outermost fcn is a boolean and there are certain places within the inner functions where it may become apparent that the return value is false. In this case I'd like to halt the computation immediately and return false. My current approach is to have...
0
1294
by: Dan D. | last post by:
We are running an IIS Server on W2K3 Server. We have 20 or 30 ASP.NET 1.1 applications. Recently I have converted an existing 1.1 application to use the 2.0 framework. After testing and a little code reconstruction it was ready to post as 2.0. I removed the application from production IIS and re-deployed it from VS.NET 2005. I created a new application pool for it and set the framework for the application to 2.0. The application is...
5
3901
by: Ben | last post by:
Hi; I use ain asp.net the CreateUserWizard control for new users. When it's done, i want to redirect them to another page (modifyprofile.aspx). This works with the code below. My question is: if i suppress the line "return false" in the javascript function profile(), the user is created but not redirected to the other aspx page. Can anybody explain me why?
5
8688
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
0
8984
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
8823
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
9530
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
9363
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
9312
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
8237
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
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3300
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 we have to send another system
3
2206
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.