"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="JavaScript" type="text/javascript">
<!--
function validate() {
var x = "0";
if (document.subinfo.Name.value == "") {
alert("You must enter your First Name.");
document.subinfo.Name.focus();
x.value = "1";
return(false); }
if (document.subinfo.Email.value == "" ||
document.subinfo.Email.value.indexOf("@") == -1 ||
document.subinfo.Email.value.indexOf(".") == -1) {
alert("Invalid email address. Please re-enter it.");
document.subinfo.Email.focus();
// return false; }
x.value = "1"; }
if (x.value == "0") {
launchwin('thanks.html','confirmation','height=200 ,width=280');
document.subinfo.submit();
location.href = "default.html"; }
}
-->
</script>
<form action="mailto:myemail@mycompany.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="javascript:validate()">
<img src="gfx/send.gif" name="send" width="42" height="18"
alt="Send Form" />
</a>
<a href="javascript:document.inquiries.reset()">
<img src="gfx/clear.gif" name="clear" width="42" height="18"
alt="Clear Form" />
</a>
</form>
<********** END CODE **********>
Thanks,
Kurt | | | | re: "return false" gives a blank page with the word "false" ?
wrote on 15 feb 2006 in comp.lang.javascript:
[color=blue]
> 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="JavaScript" type="text/javascript">[/color]
do not use language="JavaScript"
[color=blue]
> <!--[/color]
do not use <!--
[color=blue]
> function validate() {
> var x = "0";
>
> if (document.subinfo.Name.value == "") {
> alert("You must enter your First Name.");
> document.subinfo.Name.focus();
> x.value = "1";
> return(false); }[/color]
should be:
return false; }
but then the x.value = "1"; would not be usefull,
so delete the return false here
[color=blue]
>
> if (document.subinfo.Email.value == "" ||
> document.subinfo.Email.value.indexOf("@") == -1 ||
> document.subinfo.Email.value.indexOf(".") == -1) {
> alert("Invalid email address. Please re-enter it.");
> document.subinfo.Email.focus();
> // return false; }[/color]
well done //
[color=blue]
> x.value = "1"; }
>
> if (x.value == "0") {
> launchwin('thanks.html','confirmation','height=200 ,width=280');[/color]
what is launchwin() ???????????
[color=blue]
> document.subinfo.submit();
> location.href = "default.html"; }[/color]
[color=blue]
>}
> -->
> </script>
>
> <form action="mailto:myemail@mycompany.com" id="subinfo" method="post"
> name="subinfo" enctype="text/plain">
> <input name="Name" size="24" /><br /><br />[/color]
do not use <br /> but <br>
[color=blue]
> <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="javascript:validate()">
> <img src="gfx/send.gif" name="send" width="42" height="18"
> alt="Send Form" />
> </a> [/color]
href="javascript: is a bad idea, better do:
<form onsubmit='validate()' ...
and
<input src="gfx/send.gif" type='image' alt="Send Form">
[color=blue]
> <a href="javascript:document.inquiries.reset()">
> <img src="gfx/clear.gif" name="clear" width="42" height="18"
> alt="Clear Form" />
> </a>[/color]
same here:
<img onclick='document.inquiries.reset()' src="gfx/clear.gif"
style='cursor:pointer;'>
[color=blue]
> </form>
>
> <********** END CODE **********>
>
> Thanks,
> Kurt
>
>[/color]
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) | | | | re: "return false" gives a blank page with the word "false" ?
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="javascript: fnc1();void(0);">adsasd</a>
</body>
</html>
HTH
Elias
<kurtj@ev1.net> wrote in message
news:1139960156.221596.201430@z14g2000cwz.googlegr oups.com...[color=blue]
> 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="JavaScript" type="text/javascript">
> <!--
> function validate() {
> var x = "0";
>
> if (document.subinfo.Name.value == "") {
> alert("You must enter your First Name.");
> document.subinfo.Name.focus();
> x.value = "1";
> return(false); }
>
> if (document.subinfo.Email.value == "" ||
> document.subinfo.Email.value.indexOf("@") == -1 ||
> document.subinfo.Email.value.indexOf(".") == -1) {
> alert("Invalid email address. Please re-enter it.");
> document.subinfo.Email.focus();
> // return false; }
> x.value = "1"; }
>
> if (x.value == "0") {
> launchwin('thanks.html','confirmation','height=200 ,width=280');
> document.subinfo.submit();
> location.href = "default.html"; }
> }
> -->
> </script>
>
> <form action="mailto:myemail@mycompany.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="javascript:validate()">
> <img src="gfx/send.gif" name="send" width="42" height="18"
> alt="Send Form" />
> </a>
> <a href="javascript:document.inquiries.reset()">
> <img src="gfx/clear.gif" name="clear" width="42" height="18"
> alt="Clear Form" />
> </a>
> </form>
>
> <********** END CODE **********>
>
> Thanks,
> Kurt
>[/color] | | | | re: "return false" gives a blank page with the word "false" ?
Evertjan. wrote:[color=blue][color=green]
>><form action="mailto:myemail@mycompany.com" id="subinfo" method="post"
>>name="subinfo" enctype="text/plain">
>> <input name="Name" size="24" /><br /><br />[/color]
>
>
> do not use <br /> but <br>
>[/color]
He might be using XHTML.
--
Ian Collins. | | | | re: "return false" gives a blank page with the word "false" ?
Ian Collins said the following on 2/14/2006 7:57 PM:[color=blue]
> Evertjan. wrote:[color=green][color=darkred]
>>> <form action="mailto:myemail@mycompany.com" id="subinfo" method="post"
>>> name="subinfo" enctype="text/plain">
>>> <input name="Name" size="24" /><br /><br />[/color]
>>
>>
>> do not use <br /> but <br>
>>[/color]
> He might be using XHTML.
>[/color]
Giving XHTML to IE is a recipe for disaster.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/ | | | | re: "return false" gives a blank page with the word "false" ?
Randy Webb wrote:[color=blue]
> Ian Collins said the following on 2/14/2006 7:57 PM:
>[color=green]
>> Evertjan. wrote:
>>[color=darkred]
>>>> <form action="mailto:myemail@mycompany.com" id="subinfo" method="post"
>>>> name="subinfo" enctype="text/plain">
>>>> <input name="Name" size="24" /><br /><br />
>>>
>>>
>>>
>>> do not use <br /> but <br>
>>>[/color]
>> He might be using XHTML.
>>[/color]
>
> Giving XHTML to IE is a recipe for disaster.
>[/color]
There's plenty out there and <br /> is the correct compatibility option.
--
Ian Collins. | | | | re: "return false" gives a blank page with the word "false" ?
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:[color=blue][color=green]
> > <script language="JavaScript" type="text/javascript">[/color]
> do not use language="JavaScript"[/color]
[color=blue][color=green]
> > <!--[/color]
> do not use <!--[/color]
Why should I not use language="JavaScript" 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). | | | | re: "return false" gives a blank page with the word "false" ?
Kurt wrote:[color=blue]
> 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:
>[color=green][color=darkred]
>>><script language="JavaScript" type="text/javascript">[/color]
>>
>>do not use language="JavaScript"[/color]
>
>[color=green][color=darkred]
>>><!--[/color]
>>
>>do not use <!--[/color]
>
>
> Why should I not use language="JavaScript" or <!-- ??
>[/color]
language="JavaScript" isn't a valid script attribute in HTML 4 or XHTML,
try a validator on your page.
--
Ian Collins. | | | | re: "return false" gives a blank page with the word "false" ?
Ian Collins wrote on 16 feb 2006 in comp.lang.javascript:
[color=blue]
> Kurt wrote:[color=green][color=darkred]
>>>do not use language="JavaScript"[/color]
>>[color=darkred]
>>>><!--
>>>do not use <!--[/color]
>> Why should I not use language="JavaScript" or <!-- ??[/color]
> language="JavaScript" isn't a valid script attribute in HTML 4 or XHTML,
> try a validator on your page.[/color]
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) | | | | re: "return false" gives a blank page with the word "false" ?
According to validator.w3.org, 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 | | | | re: "return false" gives a blank page with the word "false" ?
Kurt wrote on 16 feb 2006 in comp.lang.javascript:
[color=blue]
> According to validator.w3.org, 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[/color]
[...]
Please quote what you are replying to.
This is usenet, not email.
If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers. <http://www.safalra.com/special/googlegroupsreply/>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) | | | | re: "return false" gives a blank page with the word "false" ?
Ian Collins wrote:
[color=blue]
> Randy Webb wrote:[color=green]
>> Ian Collins said the following on 2/14/2006 7:57 PM:[color=darkred]
>>> Evertjan. wrote:
>>>>> <form action="mailto:myemail@mycompany.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.[/color]
>> Giving XHTML to IE is a recipe for disaster.[/color]
>
> There's plenty out there[/color]
Two wrongs make no right.
[color=blue]
> and <br /> is the correct compatibility option.[/color]
`<br />' is equivalent to `<br>>' in HTML. The correct "compatibility
option" is `<br></br>'; if you read anything different in the non-normative
XHTML 1.0 Appendix C, it is _worng_. The only problem is that there may
be borken UAs out there that cannot parse this correct markup correctly.
Therefore, XHTML should _never_ be served as text/html (and IE does not
support the proper media type application/xhtml+xml):
<URL:http://hixie.ch/advocacy/xhtml>
PointedEars | | | | re: "return false" gives a blank page with the word "false" ?
Ian Collins wrote:
[color=blue]
> Kurt wrote:[color=green]
>> Why should I not use language="JavaScript" or <!-- ??
>>[/color]
> language="JavaScript" isn't a valid script attribute in HTML 4 or XHTML,
> [...][/color]
It is Valid in the Transitional subsets of HTML 4.01 and XHTML 1.0.
It is deprecated and unnecessary, though.
PointedEars | | | | re: "return false" gives a blank page with the word "false" ?
Kurt wrote:
[color=blue]
> I have a question about Evertjan's response:[color=green][color=darkred]
>> > <script language="JavaScript" type="text/javascript">[/color]
>> do not use language="JavaScript"[color=darkred]
>> > <!--[/color]
>> do not use <!--[/color]
>
> Why should I not use language="JavaScript" or <!-- ??[/color]
Enough said about the `language' attribute.
About trying to comment out scripts this way:
In HTML, it is error-prone. The `script' element's content is CDATA and
is passed as-is to the script engine. In ECMAScript implementations, `<',
`!', and `--' are operators, and you provide no valid operand: syntax
error. Furthermore, there is no standards compliant UA out there that
requires it; HTML versions prior to 3.2, which did not define the `script'
element yet, have been obsoleted by RFC2854 in 2000 CE (six years ago!).
In XHTML, it is nonsense. There has been no XHTML version that did not
declare the `script' element, so there is no need to hide anything.
Furthermore, in XHTML the `script' element's content is PCDATA, and is
parsed by the XML parser before it is passed to the script engine.
However, in XML applications like XHTML `<!-- ... -->' are _comments_
and an XML parser is allowed to remove all comments before building the
parse tree. You could and will end up with an empty `script' element:
<script/>
See previous discussions on this, it has been discussed _ad nauseam_ before.
[color=blue]
> PS: I am using XHTML [...][/color]
Do not do that, unless you have to.
PointedEars |  | Similar JavaScript / Ajax / DHTML bytes | | | /bytes/about
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 226,471 network members.
|