Returning value is blank

S

Simulacrom1

Hi! :)

I am having a very strange problem. The code listed below works fine
with one exception - it returns a blank. The JavaScript code tells it
to set the value to "loginContractor" and when I step through the
JavaScript it does just that. But when the PHP program sees the
incoming information - it sees it as a blank. So I'm asking here first
to see if anyone has any ideas on the JavaScript side. If not, I'll try
the PHP side of things.

Thanks in advance for any ideas/help you may be able to give.

Mark

Webpage source code to follow:



<!-- The Command = -->
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>
<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="Generator" content="Mark's PHP Classes v1.0">
<meta name="Copyright" Content="Copyright (c) 2008. All rights reserved.">
<meta name="Author" content="Mark Manning">
<script language="JavaScript">
////////////////////////////////////////////////////////////////////////////////
// Set global browser boolean flags
// Originally taken from Danny Goodman's JavaScript Bible.
////////////////////////////////////////////////////////////////////////////////
var isIE = document.all;
var isIE7 = isIE && window.XMLHttpRequest &&
window.ActiveXObject;
var isIE6 = isIE && document.implementation;
var isgteIE6 = isIE7 || isIE6;
var isIE5 = isIE && window.print && !isgteIE6;
var isIEDOM2 = isIE5 || isgteIE6;
var isIE4 = isIE && !isIEDOM2 &&
navigator.cookieEnabled;
var isIE3 = isIE && !isIE4 && !isIEDOM2;
var isNS = navigator.mimeTypes && !isIE;
var isNS3 = isNS && !navigator.language;
var isNS4 = document.layers;
var isNS6 = document.getElementById && !isIE;
var isNS7 = isNS6;
var isNS71 = document.designMode;
var isNSDOM2 = isNS6;
var isDOM2 = isIEDOM2 || isNSDOM2;

////////////////////////////////////////////////////////////////////////////////
// doesExist. A function to detect whether something exists or not.
// Copyright (c) 2009. All rights reserved.
////////////////////////////////////////////////////////////////////////////////
function doesExist(e)
{
if( (typeof(e) == "undefined") || (e == "") || (e == null) ){
return false;
}

return true;
}

////////////////////////////////////////////////////////////////////////////////
// Simple cross-browser function to get an element.
// by Jason D. Agostoni @ jason ATNOSPAM agostoni DOTNOSPAM net
// Modified by Mark Manning @ www.sim1.us
////////////////////////////////////////////////////////////////////////////////
function getElement(psID)
{
if( isNS && isNS3 ){
alert( "This program does not support Netscape versions earlier than
v4.7" );
return null;
} // We do not deal with NS3 or older
if( isIE3 || isIE4 ){
alert( "This program does not support Internet Explorer versions
earlier than v6.0" );
return null;
} // We do not deal with IE4 or older

if( document.all ){
return document.all[psID];
}
else if( document.getElementById ){
var myID = document.getElementById( psID );

if( !doesExist(myID) ){ myID = document.getElementsByName( psID ); }
return myID;
}
else {
for( iLayer = 1; iLayer < document.layers.length; iLayer++ ){
if( document.layers[iLayer].id == psID ){
return document.layers[iLayer];
}
}
}

return Null;
}
////////////////////////////////////////////////////////////////////////////////
// Function: setValue( eid, v ).
// Copyright (c) 2008. All rights reserved.
////////////////////////////////////////////////////////////////////////////////
function setValue( eid, v )
{
var e = getElement( eid );

if( e == null ){ return false; }

e.value = v;
return true;
}



</script>
<noscript>
If you are seeing this, then your browser either has
JavaScript turned off or it doesn't support JavaScript.
In either case you need to either enable JavaScript
or upgrade your browser so it can handle JavaScript.
Otherwise you will not be able to use this program.
Thank you.
</noscript>
<style>
.notYet {
background-color:white;
color:#ee0000;
font:bold 24pt 'Courier New';
border:1px solid black;
position:absolute;
top:100px;
left:5;
width:800px;
height:100px;
}
.TitleDiv {
background-color:#ccccff;
color:#000000;
border:1px solid black;
position:absolute;
left:5px;
top:5px;
width:800px;
height:75px;
}
.font_1 {
font:18pt "Courier New";;
font-weight:bold;
color:black;
z-index:1;
position:absolute;
left:5px;
top:5px;
}
.font_2 {
font:52pt "Courier New";;
color:white;
position:absolute;
left:5px;
top:0px;
}
.font_3 {
font:24pt "Courier New";;
font-weight:bold;
color:black;
position:absolute;
left:475px;
top:40px;
}
.font_4 {
font:8pt "Courier New";;
color:black;
position:absolute;
left:675px;
top:60px;
}
.ContractorLogon {
background-color:#88ff88;
color:#000000;
border:1px solid black;
position:absolute;
top:100px;
left:200px;
width:400px;
height:200px;
}
.CustomerLogon {
background-color:#eeee00;
color:#000000;
border:1px solid black;
position:absolute;
top:310px;
left:200px;
width:400px;
height:100px;
}
.href_1 {
font:8pt Arial;
}
.title_2 {
font:bold 12pt 'Courier New';
}
.title_3 {
font:bold 8pt 'Courier New';
}
.NewsBox {
background-color:#f4f4ff;
color:#000000;
border:1px solid black;
position:absolute;
top:100px;
left:610px;
width:195px;
height:400px;
}
.newsTitle_1 {
font:bold 18pt 'Courier New';
text-align:center;
}
.newsTitle_2 {
font:8pt 'Courier New';
}
.newsTitle_3 {
font:bold 8pt 'Courier New';
}
.updatesBox {
background-color:#ddffff;
color:#000000;
border:1px solid black;
position:absolute;
top:100px;
left:5px;
width:185px;
height:400px;
}
.updatesTitle_1 {
font:bold 18pt 'Courier New';
text-align:center;
}
.updatesTitle_2 {
font:8pt 'Courier New';
}
.updatesTitle_3 {
font:bold 8pt 'Courier New';
}
</style>

</head>
<body>
<div class="TitleDiv" name='Title0' id='Title0'>
<form action='index.php' method='post'>
<input name="theCmd" id="theCmd" type="hidden" value="">
<font class="font_1">The</font>
<font class="font_2">Contractor's</font>
<font class="font_3">Friend</font>
<font class="font_4">by Simulacron I</font>

</form>
</div><div class="ContractorLogon" name='Login0' id='Login0'>
<form action='index.php' method='post'>
<input name="theCmd" id="theCmd" type="hidden" value="">
<table border='0' width='100%'>
<tr>
<td colspan='3' align='center'><font style='font:bold 18pt "Courier
New'>Contractor's Login</font></td>
</tr>
<tr>

<td colspan='3' align='center'>
<table style="border:0px solid black"><tr>
<td align='right' class='title_2'>Username:</td>
<td align='left'><input name='uid' type='text' size='40'
maxlength='35' value=' '></td>
</tr></td></table>
</td>
</tr>
<tr>

<td colspan='3' align='center'>
<table style="border:0px solid black">
<tr>
<td align='right' class='title_2'>Password:</td>
<td align='left'><input name='pwd' type='password' size='40'
maxlength='35'></td>
</tr>
</table>
</td>

</tr>
<tr><td height='20px'>&nbsp;</td></tr>
<tr>
<td colspan='3' align='center'><input type='submit' value='Log Me In!'
style="height:30px;width:150px;" onClick="Javascript:return
setValue('theCmd', 'loginContractor');"></td>
</tr>
<tr>
<td colspan='3' align='center' nowrap height='20px'><a
href="index.php?theCmd=newUser_1" class="href_1">New users click
here</a>
</td>

</tr>
<tr>
<td align='left'><a href='index.php?theCmd=forgotUID'>
<font style='font:8pt Arial'>Forgot your <b>USERNAME?</b></font></a>
</td>
<td align='center'><a href='index.php?nu=1'> </td>
<td align='right'><a href='index.php?theCmd=forgotPWD'>

<font style='font:8pt Arial'>Forgot your <b>PASSWORD?</b></font></a>
</td>
</tr>
</table>
</form>
</div><div class="CustomerLogon" name='Login1' id='Login1'>
<form action='index.php' method='post'>
<input name="theCmd" id="theCmd" type="hidden" value="customer">
<table border='0' width='100%'>

<tr>
<td colspan='3' align='center'><font style='font:bold 18pt "Courier
New'>Customer's Login</font></td>
</tr>
<tr>
<td colspan='3' align='center'>
<table style="border:0px solid black"><tr>
<td align='right' class='title_2'>Invoice #:</td>
<td align='left'><input name='invoice' type='text' size='40'
maxlength='35' value=''></input></td>

</tr></td></table>
</td>
</tr>
<tr>
<td colspan='3' align='center'><input type='submit' value='Continue'
style="height:30px;width:150px;"></td>
</tr>
</table>
</form>
</div><div class="NewsBox" name='Login0' id='Login0'>

<form action='index.php' method='post'>
<input name="theCmd" id="theCmd" type="hidden" value="">
<table border='0' width='100%'>
<tr>
<td class="newsTitle_1">News</td>
</tr>
<tr>
<td class="newsTitle_2">This is the news box</td>

</tr>
</table>
</form>
</div><div class="updatesBox" name='Login0' id='Login0'>
<form action='index.php' method='post'>
<input name="theCmd" id="theCmd" type="hidden" value="">
<table border='0' width='100%'>
<tr>
<td class="updatesTitle_1">Updates</td>

</tr>
<tr>
<td class="updatesTitle_2">This is the updates box</td>
</tr>
</table>
</form>
</div></body>
</html>


End of webpage source code.

(If this is too warped for you due to how newsgroups format things - let
me know and I will e-mail you a zip file with the source code in it.)
 
T

Thomas 'PointedEars' Lahn

Simulacrom1 said:
I am having a very strange problem. The code listed below works fine

No, it doesn't.
with one exception - it returns a blank.

Again, a blank -- what?
The JavaScript code tells it
to set the value to "loginContractor" and when I step through the
JavaScript it does just that.

Does it? Let's see:

<td colspan='3' align='center'><input type='submit' value='Log Me In!'
style="height:30px;width:150px;" onClick="Javascript:return
setValue('theCmd', 'loginContractor');"></td>

What do you think will returning a value to the `click' listener of a table
cell do?
But when the PHP program sees the
incoming information - it sees it as a blank. So I'm asking here first
to see if anyone has any ideas on the JavaScript side.

It's FUBAR, especially the getElement() function.
[...]
Webpage source code to follow:



<!-- The Command = -->

Besides that it doesn't serve a purpose, it doesn't belong there as it
triggers Quirks/Compatibility Mode ...
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'>

.... but then you are not going for Standards Compliance Mode anyway, are you?

<html lang='en'>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

Hopefully the HTTP Content-Type header looks the same.

<meta name="Generator" content="Mark's PHP Classes v1.0">
<meta name="Copyright" Content="Copyright (c) 2008. All rights reserved.">

Copyright *by whom*? But I'm sure nobody will want to copy *that*.
<meta name="Author" content="Mark Manning">

Ever heard of Dublin Core Metadata?

<http://dublincore.org/documents/dcmi-terms/>
<script language="JavaScript">

At least

<script type="text/javascript">

since ten years now (HTML 4.01).

////////////////////////////////////////////////////////////////////////////////
// Set global browser boolean flags
// Originally taken from Danny Goodman's JavaScript Bible.

Take it back, and ask for a refund.
////////////////////////////////////////////////////////////////////////////////
var isIE = document.all;
[...]

Dump this.
////////////////////////////////////////////////////////////////////////////////
// doesExist. A function to detect whether something exists or not.
// Copyright (c) 2009. All rights reserved.
////////////////////////////////////////////////////////////////////////////////
function doesExist(e)
{
if( (typeof(e) == "undefined") || (e == "") || (e == null) ){
return false;
}

return true;
}

Dump this, too. `!!e' does the same.
////////////////////////////////////////////////////////////////////////////////
// Simple cross-browser function to get an element.
// by Jason D. Agostoni @ jason ATNOSPAM agostoni DOTNOSPAM net
// Modified by Mark Manning @ www.sim1.us
////////////////////////////////////////////////////////////////////////////////
function getElement(psID)
{
if( isNS && isNS3 ){
[...]

And this.
////////////////////////////////////////////////////////////////////////////////
// Function: setValue( eid, v ).
// Copyright (c) 2008. All rights reserved.
////////////////////////////////////////////////////////////////////////////////
function setValue( eid, v )
{
var e = getElement( eid );

if( e == null ){ return false; }

e.value = v;
return true;
}

And this. You don't need IDs to refer to form controls, use `names' (which
you need for submission anyway) and the `elements' collection of form objects.
</script>
<noscript>
If you are seeing this, then your browser either has
JavaScript turned off or it doesn't support JavaScript.
In either case you need to either enable JavaScript
or upgrade your browser so it can handle JavaScript.
Otherwise you will not be able to use this program.
Thank you.
</noscript>

Dump this, too. Your users are not interested at all in pointless
technobabble, they simply want the site to *work* as best as it can
in their UA.
<style>

.notYet {
background-color:white;
color:#ee0000;

Not web-safe. And avoid mixing names and hex-values.
font:bold 24pt 'Courier New';

What about other users that have a different font resolution, and don't have
this font available? Use `%' or `em' as units, `px' if you must. Never
`pt' except maybe for printing.
border:1px solid black;
position:absolute;
top:100px;
left:5;
^
I need to have *5* /eggs/ *left* in my fridge for that omelette recipe?

(Use said:
width:800px;
height:100px;

What about users with a smaller viewport?
}
.TitleDiv {
background-color:#ccccff;

#ccf degrades gracefully.
color:#000000;

#000 degrades gracefully.

border:1px solid black;

Why not #000 while you are at it?
position:absolute;
left:5px;
top:5px;
width:800px;

See above.
height:75px;

See above.
}
.font_1 {
font:18pt "Courier New";;

See above. There is also an extra `;' here.
font-weight:bold;

Why not `font: 18... bold font-families, generic-family'?

[...]
.ContractorLogon {
background-color:#88ff88;

Not Web-safe, probably not accessible.
[...]
position:absolute;

Forget about the whole absolute-positioning nonsense. This isn't PDF.
[...]
background-color:#eeee00;

See above.
color:#000000;

See above.
[...]
.href_1 {
font:8pt Arial;
}

See above.

We could have done without all that garbage, thank you very much.
</head>
<body>
<div class="TitleDiv" name='Title0' id='Title0'>

That `div' element does not serve a purpose, and it is not Valid.

<form action='index.php' method='post'>

Consider

<form action="./" method="post">

instead.
<input name="theCmd" id="theCmd" type="hidden" value="">

You don't need IDs, see above.
<font class="font_1">The</font>
<font class="font_2">Contractor's</font>
<font class="font_3">Friend</font>
<font class="font_4">by Simulacron I</font>

Where have you been the last decade? Forget about `font' elements,
</form>
</div><div class="ContractorLogon" name='Login0' id='Login0'>
<form action='index.php' method='post'>

Why two forms?
[...]
</html>


End of webpage source code.

Thanks, I had quite enough of it. 350+ lines of *junk* in a posting?
You must be kidding.
(If this is too warped for you due to how newsgroups format things - let
me know and I will e-mail you a zip file with the source code in it.)

Warped? I'm about to go to Warp speed to get as far away from this as
possible, if you mean that.


Pointed"Energize!"Ears
 
T

Thomas 'PointedEars' Lahn

Thomas 'PointedEars' Lahn wrote/:
Does it? Let's see:

<td colspan='3' align='center'><input type='submit' value='Log Me In!'
style="height:30px;width:150px;" onClick="Javascript:return
setValue('theCmd', 'loginContractor');"></td>

What do you think will returning a value to the `click' listener of a table
cell do?

Ahh, there's an `input' in the junk :) Don't do that, cancel the submit
event of the form instead:

<form ... onsubmit="setValue('theCmd', 'loginContractor')">
...
</form>

And remove the `Javascript:' -- there a superfluous label at best, an error
at worst.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Thomas 'PointedEars' Lahn wrote/:
Does it? Let's see:

<td colspan='3' align='center'><input type='submit' value='Log Me In!'
style="height:30px;width:150px;" onClick="Javascript:return
setValue('theCmd', 'loginContractor');"></td>

[...] Don't do that, cancel the submit event of the form instead:

<form ... onsubmit="setValue('theCmd', 'loginContractor')">

<form ... onsubmit="return setValue('theCmd', 'loginContractor')">


PointedEars
 
M

Mark Manning

Hmmmm - let me think about all you have said. Thanks.

In the other thread you say you can not get to http://tcf.sim1.biz. Ah...I
think I said tcf.sim1.us. Sorry - typo.

Later.
 
T

Thomas 'PointedEars' Lahn

M

Mark Manning

OK, .biz "works".


PointedEars

The actual problem turned out to be that my PHP scripts were generating
"theCmd" in several places. The particular "theCmd" that was being
returned hadn't been set. Have to redo some of my logic to make the
returning command variable be unique each time. :-/ Thanks for the tips
though I'll check out !!e especially since I've never heard of it before.
 
M

musicbloglist

The actual problem turned out to be that my PHP scripts were generating
"theCmd" in several places.  The particular "theCmd" that was being
returned hadn't been set.  Have to redo some of my logic to make the
returning command variable be unique each time.  :-/  Thanks for the tips
though I'll check out !!e especially since I've never heard of it before.

If !!e is a revelation ditch the "Bible" and get your hands on
Javascript: The Definitive Guide or Javascript: The Good Parts.

-James.
 
T

Thomas 'PointedEars' Lahn

Mark said:

Trim your quotes to the relevant minimum, please. Usually don't quote
signatures.

The actual problem turned out to be that my PHP scripts were generating
"theCmd" in several places.

Yes, the Validator showed duplicate IDs, and there were also duplicate names
(which isn't a problem in itself if you use name="foo[]" -- PHP's
$_REQUEST['foo[]'] stores an array then).
The particular "theCmd" that was being returned hadn't been set.

That is the likely result if you don't design with graceful degradation in
mind. Your site needs to work without DOM support, and without scripting at
all.
Have to redo some of my logic to make the
returning command variable be unique each time. :-/

Probably you didn't need to. However, I still wonder why there were several
forms. They are not necessary; you can use one form with differently named
or value'd submit buttons.
Thanks for the tips though I'll check out !!e especially since I've never
heard of it before.

Why, it is simply double negation; you can also write it as !(!e). But
actually,

function doesExist(e)
{
return !!e;
}

is not equivalent to

function doesExist(e)
{
if ((typeof e == "undefined") || (e == "") || (e == null))
{
return false;
}

return true;
}

because e.g. typeof NaN == "number", NaN != "", and NaN != null.

However, the only place where you use this is (pretty-printed)

var myID = document.getElementById(psID);
if (!doesExist(myID))
{
myID = document.getElementsByName(psID);
}

and since you negate the return value anyway, you can simply do

if (!myID)

In any case, it is foolish to assume duplicate IDs (which are invalid) to be
working (that an MSHTML quirk). If names are to be used and if the `name'
attributes are Valid, there is no reason why document.getElementsByName()
shouldn't be used in the first place (save members of collections, like form
controls which are better referred to by document.forms[...].elements[...],
this.form.elements[...], or this.elements[...], depending on the context.)


PointedEars
 
M

Mark Manning

To: Thomas 'PointedEars' Lahn <[email protected]>

Most of my code is being generated by PHP scripts which I am working on.
The PHP scripts act like Dojo, or Spyr, etc... The scripts are new (as
is the application I'm writing) and there are going to be problems with
them. Which is also why I'm not using the document standards at this
point. After I have gotten further along I plan on turning up the
requirements but right now I'm shooting for widest usage across many
browsers. Most of which are not the latest and greatest - but are more
along the lines of oldie goldies. :) So many of the things I'm doing
are to try to ensure they will work across all of the older browsers.

On the !!e - I know about !(not) but had never run across !! before.
(Sort of reminds me of a knock-knock joke actually.) As I said - I will
read up on it.

Anyway, going back to the doesExist() function, the PHP scripts generate
what is needed. I say use the function, the scripts pull in the
dependent functions to that function. The reason they are written the
way they are is so I can step into them to find out what is going on.
Or to put that another way - I probably could reduce several of the
functions I have written (or use) so they only take one line of code so
I could wind up with

function(x){ return y; }

but then you can't use FireBug on that statement because there are no
lines to break on. So some of the functions I use are that way just
because then I can set a breakpoint and start monitoring from that
location. Not that I don't like what you are saying - just that this is
how I currently have everything.

One exception I have to say on what you wrote:

"Why, it is simply double negation; you can also write it as !(!e). But
actually,

.. . .

and since you negate the return value anyway, you can simply do

if (!myID)"

I read online (forget where) that this will not work. The person gave
several examples of why using the "!myID" doesn't work and presented
code similar to what I have. The problem was that "undefined" is not
the same as "NULL" which is not the same as.... Here is one of the web
pages I read up on this. Be sure to read the comments as they are
pertinent also. :)

http://saladwithsteve.com/2008/02/javascript-undefined-vs-null.html

Also, NaN means that the variable does exist - it is just that the value
is not-a-number.

Ah. Just found another website where they discuss this. Take a look at

http://constc.blogspot.com/2008/07/undeclared-undefined-null-in-
javascript.html

The guy mentions that using (!myID) when myID=0 returns TRUE. Well,
that would mean that if myID!=0 to begin with, then !myID should return
FALSE - when it really does exist. Not something I want.

To: (e-mail address removed)

Already own it and read it. In fact, I've got four books on Javascript
with the oldest being for version 1.1. (Read the white paper on-line at
Netscape for version 1.0.) I have the Javascript:Definitive Guide,
Dynamic HTML, Javascript Bible, Sam's HTML v3.2 book (with
Javascript),and another of the O'Reilly books which I can't remember the
name right now. But more importantly - I can get online and read up on
the latest stuff if/when I need to do so.

:)
 
D

David Mark

To: Thomas 'PointedEars' Lahn <[email protected]>

Is this a carbon of an email? Thomas won't be pleased.
Most of my code is being generated by PHP scripts which I am working on.  
The PHP scripts act like Dojo, or Spyr, etc...

Odd for PHP scripts to act like that.
The scripts are new (as is the application I'm writing) and there are going to be problems with
them.  Which is also why I'm not using the document standards at this
point.

No wait, reverse that.
After I have gotten further along I plan on turning up the
requirements
but right now I'm shooting for widest usage across many

You are missing by miles. Miles and miles.
browsers.  Most of which are not the latest and greatest - but are more
along the lines of oldie goldies.  :)  So many of the things I'm doing
are to try to ensure they will work across all of the older browsers.

It's not a very good try.
On the !!e - I know about !(not) but had never run across !! before.  
(Sort of reminds me of a knock-knock joke actually.)  As I said - I will
read up on it.

Double negative. It's not meant to be a brain-teaser.
Anyway, going back to the doesExist() function, the PHP scripts generate
what is needed.  I say use the function, the scripts pull in the
dependent functions to that function.  The reason they are written the
way they are is so I can step into them to find out what is going on.  

What way?
Or to put that another way - I probably could reduce several of the
functions I have written (or use) so they only take one line of code so
I could wind up with

function(x){ return y; }

I suppose.
but then you can't use FireBug on that statement because there are no
lines to break on.  So some of the functions I use are that way just
because then I can set a breakpoint and start monitoring from that
location.  Not that I don't like what you are saying - just that this is
how I currently have everything.

We saw how you have everything. Like it or not, you have profound
issues.
One exception I have to say on what you wrote:

"Why, it is simply double negation; you can also write it as !(!e).  But
actually,

.  .  .

and since you negate the return value anyway, you can simply do

  if (!myID)"

I read online (forget where) that this will not work.  The person gave

Treat anything you read online as if you saw it on the television.
several examples of why using the "!myID" doesn't work and presented
code similar to what I have.  The problem was that "undefined" is not
the same as "NULL" which is not the same as....  Here is one of the web
pages I read up on this.  Be sure to read the comments as they are
pertinent also.  :)

http://saladwithsteve.com/2008/02/javascript-undefined-vs-null.html
Also, NaN means that the variable does exist - it is just that the value
is not-a-number.
Ah.  Just found another website where they discuss this.  Take a lookat

http://constc.blogspot.com/2008/07/undeclared-undefined-null-in-
javascript.html
:)


The guy mentions that using (!myID) when myID=0 returns TRUE.  Well,
that would mean that if myID!=0 to begin with, then !myID should return
FALSE - when it really does exist.  Not something I want.

I don't follow.
To: (e-mail address removed)

This is not a blog. Please see the FAQ, specifically the section on
posting.
Already own it and read it.  In fact, I've got four books on Javascript
with the oldest being for version 1.1.  (Read the white paper on-line at
Netscape for version 1.0.)  I have the Javascript:Definitive Guide,
Dynamic HTML, Javascript Bible, Sam's HTML v3.2 book (with
Javascript),and another of the O'Reilly books which I can't remember the
name right now.  But more importantly - I can get online and read up on
the latest stuff if/when I need to do so.

See the section on the books too.
 
R

RobG

To: Thomas 'PointedEars' Lahn <[email protected]> [...]
and since you negate the return value anyway, you can simply do

  if (!myID)"

I read online (forget where) that this will not work.  The person gave
several examples of why using the "!myID" doesn't work and presented
code similar to what I have.

The value of myID is the return from a call to
document.getElementById, which is specified to either return a
reference to an element or null. Therefore the above will "work"
provided you maintain that context.

<URL: http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-getElBId >


[...]
To: (e-mail address removed)

Please learn to quote properly
Already own it and read it.  In fact, I've got four books on Javascript
with the oldest being for version 1.1.  (Read the white paper on-line at
Netscape for version 1.0.)  I have the Javascript:Definitive Guide,
Dynamic HTML, Javascript Bible, Sam's HTML v3.2 book (with
Javascript),and another of the O'Reilly books which I can't remember the
name right now.  But more importantly - I can get online and read up on
the latest stuff if/when I need to do so.

For advice on javascript books, see the FAQ:

<URL: http://www.jibbering.com/faq/ >

Ditch the Goodman book as that seems to be the source of your browser
sniffing and is generally panned in this group. A book on HTML 3.2 is
likely junk (v 4 has been around for over 10 years) and surely won't
teach you much about javascript. Flanagans's The Definitive Guide is
OK provided you have the latest version (5) and have read the errata
(see the FAQ). Crockford's Javascript: The Good Parts is OK too, but
it's more about his personal insights rather than a text for learning
scripting.
 
T

Thomas 'PointedEars' Lahn

Mark said:
To: Thomas 'PointedEars' Lahn <[email protected]>

E-mail is elsewhere, and "trimming to the relevant minimum" does not mean
quoting nothing at all. RTFFAQ.
Most of my code is being generated by PHP scripts which I am working on.
The PHP scripts act like Dojo, or Spyr, etc...

Since I avoid Dojo, Spry, etc. like the plague for good reasons, I don't
know what that is supposed to mean.
The scripts are new (as is the application I'm writing) and there are
going to be problems with them. Which is also why I'm not using the
document standards at this point.

That doesn't make sense. The "document standards", as you call them, are
going to reduce the number of problems you have.

After I have gotten further along I plan on turning up the requirements
but right now I'm shooting for widest usage across many browsers.

Then you are heading straight in the wrong direction. Currently you are
relying on not interoperable error-correction, and in some cases on pure
chance of working.
Most of which are not the latest and greatest - but are more along the
lines of oldie goldies. :)

That doesn't make any sense. With your current script code you are
targeting the latest browsers only, despite all the sniffing.
So many of the things I'm doing are to try to ensure they will work
across all of the older browsers.

You are doing the exact opposite instead.
Anyway, going back to the doesExist() function, the PHP scripts generate
what is needed.

Needed != "working" != correct
I say use the function, the scripts pull in the dependent functions to
that function.

That doesn't make sense.
The reason they are written the way they are is so I can step into them
to find out what is going on. Or to put that another way - I probably
could reduce several of the functions I have written (or use) so they
only take one line of code so I could wind up with

function(x){ return y; }

but then you can't use FireBug on that statement because there are no
lines to break on.

Nobody told you to use an anonymous functions, to remove all newlines, or to
write single-line functions (how did you get that incredibly stupid idea?).
Nevertheless, you can use Firebug on that line.
So some of the functions I use are that way just
because then I can set a breakpoint and start monitoring from that
location. Not that I don't like what you are saying - just that this is
how I currently have everything.

One exception I have to say on what you wrote:

"Why, it is simply double negation; you can also write it as !(!e). But
actually,

.. . .

and since you negate the return value anyway, you can simply do

if (!myID)"

I read online (forget where) that this will not work.

Then you have read something wrong (which isn't surprising since about 90+%
on the Web is garbage) because it has worked for me for a decade or so and
is not going to stop functioning suddenly.
The person gave several examples of why using the "!myID" doesn't work
and presented code similar to what I have.

Either you misunderstood or you didn't explain the whole context (like in
your other OP), or (as likely) the person didn't know what they were talking
about.
The problem was that "undefined" is not the same as "NULL"

Of course not. They are different strings. But if you mean the values
instead, there is no `NULL' to begin with in ECMAScript implementations,
which are case-sensitive. There is `null', and it type-converts to `false'
as does `undefined'.
which is not the same as....

It doesn't matter if it's loosely or strictly the same if it's
type-converted (per the `if' statement) anyway. It's the same in PHP, BTW.
Here is one of the web pages I read up on this.
Be sure to read the comments as they are pertinent also. :)

http://saladwithsteve.com/2008/02/javascript-undefined-vs-null.html

I certainly won't waste my time replacing good knowledge with script-kiddie
nonsense. Incidentally, "Schnitzelmitkartoffelsalat" is the term of the
result of uninformed Web authoring in de.ALL. So stay away from those salad
sites.
Also, NaN means that the variable does exist - it is just that the value
is not-a-number.

You don't say. And still !NaN (whereas NaN is never going to be returned by
document.getElementById() or its substitutes) results in `true'. Strange,
isn't it? (No, it isn't. All Editions of the ECMAScript Language
Specification say so and all known implementations agree.)
Ah. Just found another website where they discuss this. Take a look at

http://constc.blogspot.com/2008/07/undeclared-undefined-null-in-
javascript.html

The guy mentions that using (!myID) when myID=0 returns TRUE. Well, that
would mean that if myID!=0 to begin with, then !myID should return FALSE
- when it really does exist. Not something I want.

I means instead that neither this guy nor you do know what you are talking
about (as if that would not be obvious by now.) An ID cannot be `0' because
it MUST begin with a letter character (IOW, if you had an HTML document that
had id="0" it would not be Valid). In any case, an ID is always a *string*
in all DOMs (not a number, for the reasons mentioned before), and a
non-empty string like "0" always type-converts to `true'. RTFM.

<http://www.w3.org/TR/html4/types.html#h-6.2>
<http://www.w3.org/TR/DOM-Level-3-Core/core.html#ID-getElBId>
<https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Logical_Operators>


PointedEars
 
J

Jeremy J Starcher

On the !!e - I know about !(not) but had never run across !! before.
(Sort of reminds me of a knock-knock joke actually.) As I said - I will
read up on it.

The difference between "false" and "falsy" takes some getting used to.
Using the !!e will turn a "falsy" value into a false one...

Some people prefer that one force truthy and falsy to "true" and "false"
because it makes the intent more clear.

AFAIK there is no difference in execution between
if (element) { ... }

and

if (!!element) { ... }


(The following examples tried under:
< http://www.squarefree.com/shell/shell.html > )


a = !!1
true
a = !!0
false
a = !!""
false
a = !!"0"
true
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Mark said:
The guy mentions that using (!myID) when myID=0 returns TRUE. Well, that
would mean that if myID!=0 to begin with, then !myID should return FALSE
- when it really does exist. Not something I want.

I means instead that neither this guy nor you do know what you are talking
about (as if that would not be obvious by now.) An ID cannot be `0' because
it MUST begin with a letter character (IOW, if you had an HTML document that
had id="0" it would not be Valid). In any case, an ID is always a *string*
in all DOMs (not a number, for the reasons mentioned before), and a
non-empty string like "0" always type-converts to `true'. [...]

But as Rob correctly said, this particular conversion is not supposed to
happen anyway here. document.getElementById() and its substitutes would
either return/yield an object reference on success, or `null' or some other
false-value on failure or duplicate IDs.

(The DOM Level 2 HTML Specification defines that the return value must be a
reference to an object implementing the Element interface if there is such
an element, `null' if there is no such element, and an undefined value
otherwise (whereas these "null" and "undefined" are not to be confused with
the ECMAScript `null' and `undefined' values; the interfaces specified there
are language-independent. However, implementations' ECMAScript binding
appears to honor the `null' (or at least the falsyness of it), and one
shouldn't work with invalid markup to begin with. See also:



PointedEars
 
M

Mark Manning

Ok - on a different note....

No isIE et al eh?

Ok, would this better?

var isFocus = window.focus;
var isDocAll = document.all;
var isImages = document.images;
var isGetEBI = document.getElementById;
var isGetEBN = document.getElementsByNames;
var isLayers = document.layers;

....and then use the isXXX?
(taken from reading the http://www.jibbering.com/faq/#meta 8.6 section and
extrapolating what I've already got in the getElement function.)
 
T

Thomas 'PointedEars' Lahn

Jeremy said:
The difference between "false" and "falsy" takes some getting used to.

It should be common knowledge for a PHP programmer as well, so not exactly
news. But apparently I'm asking for too much.
Using the !!e will turn a "falsy" value into a false one...

Some people prefer that one force truthy and falsy to "true" and "false"
because it makes the intent more clear.

It can help with return values, indeed, especially when returning to
event-handlers.
AFAIK there is no difference in execution between
if (element) { ... }

and

if (!!element) { ... }

There isn't. And there shouldn't. Because:

,-[ECMAScript Language Specification, Edition 3 Final (March 2000)]
|
| 11.4.9 Logical NOT Operator ( ! )
|
| The production UnaryExpression : ! UnaryExpression is evaluated as
| follows:
|
| 1. Evaluate UnaryExpression.
| 2. Call GetValue(Result(1)).
| 3. Call ToBoolean(Result(2)).
^^^^^^^^^^^^^^^^^^^^^^^^^^
| 4. If Result(3) is true, return false.
| 5. Return true.
|
| [...]
| 12.5 The if Statement
| [...]
| The production IfStatement : if ( Expression ) Statement is evaluated
| as follows:
|
| 1. Evaluate Expression.
| 2. Call GetValue(Result(1)).
| 3. Call ToBoolean(Result(2)).
^^^^^^^^^^^^^^^^^^^^^^^^^^
| 4. If Result(3) is false, return (normal, empty, empty).
| 5. Evaluate Statement.
| 6. Return Result(5).
(The following examples tried under:
< http://www.squarefree.com/shell/shell.html > )

My, did you really need to *test* that? How borken is an implementation
if it cannot do simple type conversion using an unary operator properly? FUBAR.


PointedEars
 
T

Thomas 'PointedEars' Lahn

Mark said:
Ok - on a different note....

OK -- *what*? Haven't you still not learned how to quote properly?
No isIE et al eh?
Exactly.

Ok, would this better?

It's a start. isMethod() or isHostMethod() and the like would be better, of
course.
var isFocus = window.focus;
var isDocAll = document.all;
var isImages = document.images;
var isGetEBI = document.getElementById;
var isGetEBN = document.getElementsByNames;

That variable is not going to store a true-value anytime soon. The method
identifier is `getElementsByName'.
var isLayers = document.layers;

If you need to support Netscape 4.x and its layers model.
....and then use the isXXX?

No, you should test the features that you actually use, right before you use
them (unless you can be sure that the object reference doesn't change).

<http://PointedEars.de/scripts/test/whatami>


PointedEars
 
J

Jeremy J Starcher

It can help with return values, indeed, especially when returning to
event-handlers.

Ah...

I just got into the habit of returning explicit true and false from a
function. Forgot about that one.
There isn't. And there shouldn't. Because:


[ Spec snipped ]

I know the spec, but I have worked with more than one language/compiler
that has had a borked ! operator and would do .. "unexpected things."
Bad force of habit.

(Then again, I've also worked with an compiler for an embedded system
that couldn't manage to get orders of operations right and it took me
years to drop parens around every sub-expression, so I am doing
better...) *grin*

Need to test? No...

However, it was the quickest and easiest way to generate a handful of
examples.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top