Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #19245 > unrolled thread
| Started by | jorythompson@gmail.com |
|---|---|
| First post | 2013-04-12 10:45 -0700 |
| Last post | 2013-04-13 18:35 +0200 |
| Articles | 13 — 5 participants |
Back to article view | Back to comp.lang.javascript
trying to call onclick with document.getElement() - document.getElement() returns null jorythompson@gmail.com - 2013-04-12 10:45 -0700
Re: trying to call onclick with document.getElement() - document.getElement() returns null Jordan Thompson <jorythompson@gmail.com> - 2013-04-12 11:01 -0700
Re: trying to call onclick with document.getElement() - document.getElement() returns null Mikael Andersson <qubex2@gmail.com> - 2013-04-12 21:31 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 10:29 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-13 11:10 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 11:45 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-13 13:04 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 13:26 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-13 21:12 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-13 21:31 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Cezary Tomczyk <cezary.tomczyk@gmail.com> - 2013-04-16 20:01 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-04-16 23:13 +0200
Re: trying to call onclick with document.getElement() - document.getElement() returns null Mikael Andersson <qubex2@gmail.com> - 2013-04-13 18:35 +0200
| From | jorythompson@gmail.com |
|---|---|
| Date | 2013-04-12 10:45 -0700 |
| Subject | trying to call onclick with document.getElement() - document.getElement() returns null |
| Message-ID | <17650677-77bd-4bca-8e10-ed45772f2e9f@googlegroups.com> |
Hi all,
I am sorry if this is in the wrong group, but it (mostly) involves javascript, so I thought appropriate to post here (even though there is some php.)
When I run this, the popup shows null,null,null (indicating the document.getElementById() calls are not finding the appropriate ids.) I realize I will need to call .value on these, but will do so after I get around the null returns.
Any help here would be most welcomed!
Here is my code (note the only thing in db.php is setting up the database connection with username, password, etc. This works fine in other pages.
*****************************************************************************
options.php:
*****************************************************************************
<?php
require($_SERVER['DOCUMENT_ROOT'].'/../cgi-bin2/db.php');
function showCitiesCombo($name) {
$result = mysql_query("SELECT distinct city FROM Lot ORDER BY city");
echo 'Select a City:<br>';
echo '<select name="' . $name . '" multiple>';
echo '<form>';
while($row = mysql_fetch_array($result)) {
if ($row['city'] != "") {
echo '<option value="' . $row['city'] .'">' . $row['city'] . '</option>';
}
}
echo '</select>';
echo '</form>';
}
function showStatesCombo($name) {
$result = mysql_query("SELECT distinct usState FROM Lot ORDER BY usState");
echo 'Select a State:<br>';
echo '<select name="' . $name . '">';
echo '<form>';
while($row = mysql_fetch_array($result)) {
echo '<option value="' . $row['usState'] .'">' . $row['usState'] . '</option>';
}
echo '</select>';
echo '</form>';
}
?>
*****************************************************************************
index.php:
*****************************************************************************
<!DOCTYPE HTML>
<?php
session_start();
require($_SERVER['DOCUMENT_ROOT'].'/../cgi-bin2/options.php');
?>
<html>
<body>
<form>
<?php
showStatesCombo('cities');
showCitiesCombo('states');
echo "<br>";
?>
Street: <input type="text" name="street"><br>
<input name="buttonExecute"
onclick="searchForLots()"
type="button" value="Search" />
</form>
<br>
<div id="tableTarget"><b></b></div>
</body>
<script>
function searchForLots() {
street = document.getElementById('street');
city = document.getElementById('cities');
state = document.getElementById('state');
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("tableTarget").innerHTML=xmlhttp.responseText;
}
}
alert(street + ", " + city +", " + state);
xmlhttp.open("GET","searchForLots.php?city="+city+"&state="+state+"&street="+street, true);
xmlhttp.send();
}
</script>
</html>
[toc] | [next] | [standalone]
| From | Jordan Thompson <jorythompson@gmail.com> |
|---|---|
| Date | 2013-04-12 11:01 -0700 |
| Message-ID | <69d16aad-a7fc-4ce9-9a20-01a0af926ac7@googlegroups.com> |
| In reply to | #19245 |
duh... It seems that the control uses id= and not name= to identify itself.
On Friday, April 12, 2013 1:45:03 PM UTC-4, Jordan Thompson wrote:
> Hi all,
>
> I am sorry if this is in the wrong group, but it (mostly) involves javascript, so I thought appropriate to post here (even though there is some php.)
>
>
>
> When I run this, the popup shows null,null,null (indicating the document.getElementById() calls are not finding the appropriate ids.) I realize I will need to call .value on these, but will do so after I get around the null returns.
>
>
>
> Any help here would be most welcomed!
>
>
>
>
>
> Here is my code (note the only thing in db.php is setting up the database connection with username, password, etc. This works fine in other pages.
>
>
>
> *****************************************************************************
>
> options.php:
>
> *****************************************************************************
>
> <?php
>
> require($_SERVER['DOCUMENT_ROOT'].'/../cgi-bin2/db.php');
>
> function showCitiesCombo($name) {
>
> $result = mysql_query("SELECT distinct city FROM Lot ORDER BY city");
>
> echo 'Select a City:<br>';
>
> echo '<select name="' . $name . '" multiple>';
>
> echo '<form>';
>
> while($row = mysql_fetch_array($result)) {
>
> if ($row['city'] != "") {
>
> echo '<option value="' . $row['city'] .'">' . $row['city'] . '</option>';
>
> }
>
> }
>
> echo '</select>';
>
> echo '</form>';
>
> }
>
>
>
> function showStatesCombo($name) {
>
> $result = mysql_query("SELECT distinct usState FROM Lot ORDER BY usState");
>
> echo 'Select a State:<br>';
>
> echo '<select name="' . $name . '">';
>
> echo '<form>';
>
> while($row = mysql_fetch_array($result)) {
>
> echo '<option value="' . $row['usState'] .'">' . $row['usState'] . '</option>';
>
> }
>
> echo '</select>';
>
> echo '</form>';
>
> }
>
> ?>
>
>
>
>
>
>
>
> *****************************************************************************
>
> index.php:
>
> *****************************************************************************
>
> <!DOCTYPE HTML>
>
> <?php
>
> session_start();
>
> require($_SERVER['DOCUMENT_ROOT'].'/../cgi-bin2/options.php');
>
> ?>
>
>
>
> <html>
>
> <body>
>
> <form>
>
> <?php
>
> showStatesCombo('cities');
>
> showCitiesCombo('states');
>
> echo "<br>";
>
> ?>
>
> Street: <input type="text" name="street"><br>
>
> <input name="buttonExecute"
>
> onclick="searchForLots()"
>
> type="button" value="Search" />
>
> </form>
>
> <br>
>
> <div id="tableTarget"><b></b></div>
>
> </body>
>
>
>
> <script>
>
> function searchForLots() {
>
> street = document.getElementById('street');
>
> city = document.getElementById('cities');
>
> state = document.getElementById('state');
>
>
>
> if (window.XMLHttpRequest) {
>
> // code for IE7+, Firefox, Chrome, Opera, Safari
>
> xmlhttp=new XMLHttpRequest();
>
> } else {
>
> // code for IE6, IE5
>
> xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
>
> }
>
>
>
> xmlhttp.onreadystatechange=function() {
>
> if (xmlhttp.readyState==4 && xmlhttp.status==200) {
>
> document.getElementById("tableTarget").innerHTML=xmlhttp.responseText;
>
> }
>
> }
>
>
>
> alert(street + ", " + city +", " + state);
>
> xmlhttp.open("GET","searchForLots.php?city="+city+"&state="+state+"&street="+street, true);
>
> xmlhttp.send();
>
> }
>
> </script>
>
> </html>
[toc] | [prev] | [next] | [standalone]
| From | Mikael Andersson <qubex2@gmail.com> |
|---|---|
| Date | 2013-04-12 21:31 +0200 |
| Message-ID | <87fvyv1r7q.fsf@gmail.com> |
| In reply to | #19245 |
jorythompson@gmail.com writes:
[snip]
> *****************************************************************************
> <?php
> require($_SERVER['DOCUMENT_ROOT'].'/../cgi-bin2/db.php');
> function showCitiesCombo($name) {
> $result = mysql_query("SELECT distinct city FROM Lot ORDER BY city");
> echo 'Select a City:<br>';
> echo '<select name="' . $name . '" multiple>';
> echo '<form>';
> while($row = mysql_fetch_array($result)) {
> if ($row['city'] != "") {
[snip]
> <script>
> function searchForLots() {
> street = document.getElementById('street');
> city = document.getElementById('cities');
> state = document.getElementById('state');
>
> if (window.XMLHttpRequest) {
> // code for IE7+, Firefox, Chrome, Opera, Safari
Hi,
You should either use document.getElementsByName('street'), which
returns an array. Or change the select to: (you can in php write)
echo "<select name='$name' id='$name'>";
^^
easier to read and understand. When using " double quotes you can have
php variables inside.
Yours,
QubeX2
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-04-13 10:29 +0200 |
| Message-ID | <7902669.URqpOMyR7R@PointedEars.de> |
| In reply to | #19248 |
Mikael Andersson wrote:
> jorythompson@gmail.com writes:
>
> [snip]
>>
*****************************************************************************
>> <?php
>> require($_SERVER['DOCUMENT_ROOT'].'/../cgi-bin2/db.php');
Use “require_once”, remove the parentheses (it is not a function call), and
see <http://php.net/include_path> and <http://php.net/autoload> for how to
avoid this partially or altogether.
>> function showCitiesCombo($name) {
>> $result = mysql_query("SELECT distinct city FROM Lot ORDER BY city");
Never do it that way, see the warning in <http://php.net/mysql_query>.
>> echo 'Select a City:<br>';
>> echo '<select name="' . $name . '" multiple>';
>> echo '<form>';
Never do it that way; write templates that you include, as a first step to
separate presentation from business logic. See also: MVC.
>> while($row = mysql_fetch_array($result)) {
Make it clear that you are evaluating the right-hand side of the assignment:
while (($row = mysql_fetch_array($result))) {
But see above.
>> if ($row['city'] != "") {
>
> [snip]
>> <script>
>> function searchForLots() {
>> street = document.getElementById('street');
>> city = document.getElementById('cities');
>> state = document.getElementById('state');
You have neglected to declare your identifiers as local variables. So by
assignment they become names of properties of the Global Object, if that.
Instead:
var street = …
…
>> if (window.XMLHttpRequest) {
Insufficient and error-prone, see isHostMethod().
>> // code for IE7+, Firefox, Chrome, Opera, Safari
Learn to think in terms of layout engines and object models, not browsers.
<http://www.w3.org/TR/XMLHttpRequest/>
> You should either use document.getElementsByName('street'), which
> returns an array.
No, it does not. It returns a reference to an object that implements the
NodeList interface. In some DOM implementations (like the Gecko DOM), that
object also implements the HTMLCollection interface.
<http://www.w3.org/TR/2012/CR-html5-20121217/dom.html#dom-document-
getelementsbyname>
> Or change the select to: (you can in php write)
>
> echo "<select name='$name' id='$name'>";
> ^^
> easier to read and understand. When using " double quotes you can have
> php variables inside.
<select name="<?php echo ($name = htmlspecialchars($name, …)); ?>"
id="<?php echo $name; ?>">
or (PHP 5.4+)
<select name="<?= ($name = htmlspecialchars($name, …)); ?>"
id="<?= $name; ?>">
is recommended instead. Works better with templates, too. However, a case
could be made for DRY, so that
<select <?php
echo sprintf('name="%s" id="%*1$s"', htmlspecialchars($name, …));
?>>
becomes an option.
<http://php.net/manual/en/tutorial.firstpage.php>
<http://php.net/htmlspecialchars>
<http://php.net/manual/en/migration54.new-features.php>
<http://php.net/sprintf>
Note that IDs must be unique in an element's home subtree; names for
controls do not need to.
<http://www.w3.org/TR/2012/CR-html5-20121217/dom.html#the-id-attribute>
<http://www.w3.org/TR/2012/CR-html5-20121217/forms.html#attr-fe-name>
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2013-04-13 11:10 +0200 |
| Message-ID | <kkb7dq$ggn$1@portraits.wsisiz.edu.pl> |
| In reply to | #19250 |
W dniu 2013-04-13 10:29, Thomas 'PointedEars' Lahn pisze:
> Mikael Andersson wrote:
[...]
>>> if (window.XMLHttpRequest) {
>
> Insufficient and error-prone, see isHostMethod().
[...]
Just our of curiosity: in which environment / scenario this will not be
properly evaluated?
--
Cezary Tomczyk
http://www.ctomczyk.pl/
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-04-13 11:45 +0200 |
| Message-ID | <2061545.QaVc4i2NtW@PointedEars.de> |
| In reply to | #19252 |
Cezary Tomczyk wrote:
> W dniu 2013-04-13 10:29, Thomas 'PointedEars' Lahn pisze:
>> Mikael Andersson wrote:
> [...]
>>>> if (window.XMLHttpRequest) {
>>
>> Insufficient and error-prone, see isHostMethod().
> [...]
>
> Just our of curiosity: in which environment / scenario this will not be
> properly evaluated?
Where “XMLHttpRequest” is not a property of the object referred to by
“window”, but of another object in the scope chain.
Where the host object referred to by “window.XMLHttpRequest” does not take
kindly (read: throws unrecoverable exceptions) on being subjected to a
type-converting test.
See previous discussions that lead to isHostMethod().
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2013-04-13 13:04 +0200 |
| Message-ID | <kkbe2r$ioc$1@portraits.wsisiz.edu.pl> |
| In reply to | #19254 |
W dniu 2013-04-13 11:45, Thomas 'PointedEars' Lahn pisze:
> Cezary Tomczyk wrote:
>
>> W dniu 2013-04-13 10:29, Thomas 'PointedEars' Lahn pisze:
>>> Mikael Andersson wrote:
>> [...]
>>>>> if (window.XMLHttpRequest) {
>>>
>>> Insufficient and error-prone, see isHostMethod().
>> [...]
>>
>> Just our of curiosity: in which environment / scenario this will not be
>> properly evaluated?
>
> Where “XMLHttpRequest” is not a property of the object referred to by
> “window”, but of another object in the scope chain.
Even then isHostMethod will return true, which is not really what is
expected. By testing window.XMLHttpRequest I assume that there is really
"XMLHttpRequest" object. So, changing this is asking for trouble.
> Where the host object referred to by “window.XMLHttpRequest” does not take
> kindly (read: throws unrecoverable exceptions) on being subjected to a
> type-converting test.
You referring to 'unknown' type returned by typeof operator in Internet
Explorer, right?
> See previous discussions that lead to isHostMethod().
Yes, I know isHostMethod, but regarding "if (window.XMLHttpRequest)" I
had no problems with this feature detection. However, I know that
testing by typeof some of ActiveX objects may return 'unknown' type.
--
Cezary Tomczyk
http://www.ctomczyk.pl/
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-04-13 13:26 +0200 |
| Message-ID | <1693880.XzSgBGLykG@PointedEars.de> |
| In reply to | #19255 |
Cezary Tomczyk wrote:
> W dniu 2013-04-13 11:45, Thomas 'PointedEars' Lahn pisze:
>> Cezary Tomczyk wrote:
>>> W dniu 2013-04-13 10:29, Thomas 'PointedEars' Lahn pisze:
>>>> Mikael Andersson wrote:
>>> [...]
>>>>>> if (window.XMLHttpRequest) {
>>>>
>>>> Insufficient and error-prone, see isHostMethod().
>>> [...]
>>>
>>> Just our of curiosity: in which environment / scenario this will not be
>>> properly evaluated?
>>
>> Where “XMLHttpRequest” is not a property of the object referred to by
>> “window”, but of another object in the scope chain.
>
> Even then isHostMethod will return true,
No, it will return “false”. The point is _not_ that you should call
isHostMethod(window, "XMLHttpRequest")
or
jsx.object.isHostMethod(jsx.global, "window", "XMLHttpRequest")
instead – that would be equally wrong –, but that isHostMethod() implements
the *algorithm* to detect host methods *safely*, without implicit type
conversion.
> […]
> By testing window.XMLHttpRequest I assume that there is really
> "XMLHttpRequest" object.
No, you are assuming that there is an object in the scope chain that has a
“window” property, which is storing a reference to an object that has an
“XMLHttpRequest” property that is storing a reference to an object that,
when [[Constructed]], returns a reference to an object that implements the
“XMLHttpRequest” interface.
> So, changing this is asking for trouble.
Doing it like this is asking for trouble, because “With host objects, all
bets are off.“ (Lasse Reichstein Nielsen in cljs)
>> Where the host object referred to by “window.XMLHttpRequest” does not
>> take kindly (read: throws unrecoverable exceptions) on being subjected to
>> a type-converting test.
>
> You referring to 'unknown' type returned by typeof operator in Internet
> Explorer, right?
I am referring to any host object.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2013-04-13 21:12 +0200 |
| Message-ID | <kkcam8$smf$1@portraits.wsisiz.edu.pl> |
| In reply to | #19257 |
W dniu 2013-04-13 13:26, Thomas 'PointedEars' Lahn pisze:
> Cezary Tomczyk wrote:
>> W dniu 2013-04-13 11:45, Thomas 'PointedEars' Lahn pisze:
>>> Cezary Tomczyk wrote:
>>>> W dniu 2013-04-13 10:29, Thomas 'PointedEars' Lahn pisze:
>>>>> Mikael Andersson wrote:
>>>> [...]
>>>>>>> if (window.XMLHttpRequest) {
>>>>>
>>>>> Insufficient and error-prone, see isHostMethod().
>>>> [...]
>>>>
>>>> Just our of curiosity: in which environment / scenario this will not be
>>>> properly evaluated?
>>>
>>> Where “XMLHttpRequest” is not a property of the object referred to by
>>> “window”, but of another object in the scope chain.
>>
>> Even then isHostMethod will return true,
>
> No, it will return “false”. The point is _not_ that you should call
Can you provide me an example of when this may occur?
> isHostMethod(window, "XMLHttpRequest")
>
> or
>
> jsx.object.isHostMethod(jsx.global, "window", "XMLHttpRequest")
>
> instead – that would be equally wrong –, but that isHostMethod() implements
> the *algorithm* to detect host methods *safely*, without implicit type
> conversion.
I know both of methods, but sometimes simple statement "if
(window.XMLHttpRequest)" just do the job and I never had any problems
with that.
[...]
--
Cezary Tomczyk
http://www.ctomczyk.pl/
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-04-13 21:31 +0200 |
| Message-ID | <7595870.kvP59otsHy@PointedEars.de> |
| In reply to | #19260 |
Cezary Tomczyk wrote:
> W dniu 2013-04-13 13:26, Thomas 'PointedEars' Lahn pisze:
>> Cezary Tomczyk wrote:
>>> W dniu 2013-04-13 11:45, Thomas 'PointedEars' Lahn pisze:
>>>> Cezary Tomczyk wrote:
>>>>> W dniu 2013-04-13 10:29, Thomas 'PointedEars' Lahn pisze:
>>>>>> Mikael Andersson wrote:
>>>>> [...]
>>>>>>>> if (window.XMLHttpRequest) {
>>>>>>
>>>>>> Insufficient and error-prone, see isHostMethod().
>>>>> [...]
>>>>>
>>>>> Just our of curiosity: in which environment / scenario this will not
>>>>> be properly evaluated?
>>>>
>>>> Where “XMLHttpRequest” is not a property of the object referred to by
>>>> “window”, but of another object in the scope chain.
>>>
>>> Even then isHostMethod will return true,
>>
>> No, it will return “false”. The point is _not_ that you should call
>
> Can you provide me an example of when this may occur?
No, you just need to read more carefully. Hopefully a *working*
implementation of isHostMethod() will return a false-value if the property
in question does not exist.
>> isHostMethod(window, "XMLHttpRequest")
>>
>> or
>>
>> jsx.object.isHostMethod(jsx.global, "window", "XMLHttpRequest")
>>
>> instead – that would be equally wrong –, but that isHostMethod()
>> implements the *algorithm* to detect host methods *safely*, without
>> implicit type conversion.
>
> I know both of methods, but sometimes simple statement "if
> (window.XMLHttpRequest)" just do the job and I never had any problems
> with that.
You were asking about possible scenarios; I have provided you with them.
You should not think that “it works” justifies approaches that are
objectively unwise at best. See also: Argumentum ad crumenam.
--
PointedEars
Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Cezary Tomczyk <cezary.tomczyk@gmail.com> |
|---|---|
| Date | 2013-04-16 20:01 +0200 |
| Message-ID | <kkk3li$9ol$1@portraits.wsisiz.edu.pl> |
| In reply to | #19261 |
W dniu 2013-04-13 21:31, Thomas 'PointedEars' Lahn pisze: > Cezary Tomczyk wrote: [...] >>>>> Where “XMLHttpRequest” is not a property of the object referred to by >>>>> “window”, but of another object in the scope chain. >>>> >>>> Even then isHostMethod will return true, >>> >>> No, it will return “false”. The point is _not_ that you should call >> >> Can you provide me an example of when this may occur? > > No, you just need to read more carefully. Hopefully a *working* > implementation of isHostMethod() will return a false-value if the property > in question does not exist. I am disappointed. Instead of simple example from real life you just writing "No, you just need to read more carefully". Regarding "Where “XMLHttpRequest” is not a property of the object referred to by “window”, but of another object in the scope chain." - again, would be good to provide an example from real life, not just from theory. Just for better understanding, not guessing what author of response thought about. >>> isHostMethod(window, "XMLHttpRequest") >>> >>> or >>> >>> jsx.object.isHostMethod(jsx.global, "window", "XMLHttpRequest") >>> >>> instead – that would be equally wrong –, but that isHostMethod() >>> implements the *algorithm* to detect host methods *safely*, without >>> implicit type conversion. >> >> I know both of methods, but sometimes simple statement "if >> (window.XMLHttpRequest)" just do the job and I never had any problems >> with that. > > You were asking about possible scenarios; I have provided you with them. They are theoretical. Give me scenarios that occur in real life, not theoretical. -- Cezary Tomczyk http://www.ctomczyk.pl/
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-04-16 23:13 +0200 |
| Message-ID | <7387918.Ua4iKhALxg@PointedEars.de> |
| In reply to | #19297 |
Cezary Tomczyk wrote: > W dniu 2013-04-13 21:31, Thomas 'PointedEars' Lahn pisze: >> Cezary Tomczyk wrote: > [...] >>>>>> Where “XMLHttpRequest” is not a property of the object referred to by >>>>>> “window”, but of another object in the scope chain. >>>>> >>>>> Even then isHostMethod will return true, >>>> >>>> No, it will return “false”. The point is _not_ that you should call >>> >>> Can you provide me an example of when this may occur? >> >> No, you just need to read more carefully. Hopefully a *working* >> implementation of isHostMethod() will return a false-value if the >> property in question does not exist. > > I am disappointed. Instead of simple example from real life you just > writing "No, you just need to read more carefully". Which is exactly what you should do. You have claimed that „where ‘XMLHttpRequest’ is not a property of the object referred to by ‘window’”, “isHostMethod will return true”. However, if it is any good, it will return a false-value (trivially, “false”). > Regarding "Where “XMLHttpRequest” is not a property of the object > referred to by “window”, but of another object in the scope chain." - > again, would be good to provide an example from real life, not just from > theory. Just for better understanding, not guessing what author of > response thought about. > >>>> isHostMethod(window, "XMLHttpRequest") >>>> >>>> or >>>> >>>> jsx.object.isHostMethod(jsx.global, "window", "XMLHttpRequest") >>>> >>>> instead – that would be equally wrong –, but that isHostMethod() >>>> implements the *algorithm* to detect host methods *safely*, without >>>> implicit type conversion. >>> >>> I know both of methods, but sometimes simple statement "if >>> (window.XMLHttpRequest)" just do the job and I never had any problems >>> with that. >> >> You were asking about possible scenarios; I have provided you with them. > > They are theoretical. Give me scenarios that occur in real life, not > theoretical. An old, weathered bridge was crossing a river from high above. Someone had placed a warning sign before the bridge, saying that if you want to live you should not cross it. One day, a wild animal ran across the bridge, not heeding the warning sign. The deck of the bridge crashed instantly, and the animal fell to its death. A month later, a novice saw the warning sign and asked the master whether anyone had actually seen the bridge failing. The master said they could not remember having heard of any incident. Being confident then that the bridge was safe, the novice walked across the bridge carelessly. Its old, weathered deck crashed almost instantly, and the novice fell to their death. An apprentice heard of that incident, and asked the master what precautions should be taken in order to cross such a bridge safely. The master told them. The apprentice walked across the bridge carefully; still, its deck crashed in the middle. But thanks to their precautions, the apprentice survived. Later that day, as it was in their habit, the master walked down to the river and crossed it by the boat they had secured there. They did not remember that they placed the warning sign before the bridge as an apprentice years ago, after they almost fell to their death. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Mikael Andersson <qubex2@gmail.com> |
|---|---|
| Date | 2013-04-13 18:35 +0200 |
| Message-ID | <87ehee5qyr.fsf@gmail.com> |
| In reply to | #19250 |
Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:
> Mikael Andersson wrote:
>
>> jorythompson@gmail.com writes:
>>
>> [snip]
>>>
>
> Never do it that way; write templates that you include, as a first step to
> separate presentation from business logic. See also: MVC.
>
>>> while($row = mysql_fetch_array($result)) {
>
> Make it clear that you are evaluating the right-hand side of the assignment:
>
> while (($row = mysql_fetch_array($result))) {
>
In php its not necessary to do that. But I agree on that it makes things
clearer.
Yours,
QubeX2
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web