Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #19250

Re: trying to call onclick with document.getElement() - document.getElement() returns null

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail
Content-Type text/plain; charset="UTF-8"
Message-ID <7902669.URqpOMyR7R@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <usenet@PointedEars.de>
Organization PointedEars Software (PES)
Date Sat, 13 Apr 2013 10:29:50 +0200
User-Agent KNode/4.8.5
Content-Transfer-Encoding 8Bit
X-Face %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&.<b';Md8`dH6iqhT)6C^.Px|[=M@7=Ik[_w<%n1Up"LPQNu2m8|L!/3iby{-]A+#YE}Kl{Cw$\U!kD%K}\2jz"QQP6Uqr],./"?;=4v
Face iVBORw0KGgoAAAANSUhEUgAAADAAAAAwBAMAAAClLOS0AAAAGFBMVEXTxa4RFk5dUWANED8PFEfy7+MGBiW+n3ZNF/QuAAACaElEQVQ4jVXUwVOcMBQG8Dc7Rc4PUntdWV2uxjDpGaGeozOp1woar4jd5t/v9wLstMwsA/ntlxdCAgUc1hjTc9/JCZfGoo3wG3HdmdAWrIJRHe7GM/TmpY5VFefuVcAkkPbLIaN8rmPmjloyZxgyR3GuJ4K0AGtJ2htz8o7yqikm759fldQXaMpbDzjKAG+8v+AugVTOPO5DOjLvGtUYQwh0CPjnVMyGd+8/GfUB5nLKJDD2aLDh5HYyMDJGDwQIo2ZmZcKbowNmAdB/AzyFhrmF2MHRb0QJJfaAnwGB6orZhoykLzJtGwF/xpYxI1dswomiUj3gTuAIqCn/4C7cULwGNBtwMTk3Y4LfKB5YUaOKBKYtpplm7u0vip8tU1NWWyI/7XdcSuIDoMt6rVHMWT0DbjHPGqDqZVSa6zleLcUTcIKLoMv3ueJluALtAo9B302zPPlrtiVScRdCjXvVh3e3JpYa/jjkuC9N+LrBMlz/eAN4eQijX2EdLo6c5tGGHwLyHFtXk89dDGHwCVhG9T0S/j55AhRZgkMCmUQXJ49TnS1wnQDvw0eAh9ICeMmEFbCnPMFzjAvsWoEWEFdYEx+S0MoUZ1gT1wId8+AF3Bl2OoEu906AUHx5VLw/gXYg/x84loOah/2UYNrgiwSwGO7RfUzVBbx/kgpckumGOi6QirtD6gkLTitbnxNol47S2jVc2vsN5kPqaAHT8uUdAJM4v/DanjYOwmUjWznGfwB7sGtAtor5BgofDuzaRj4kSQAqDakTsKORa3Q3xKi3gE1fhl71KRMqrdZ2AWNNg/YOhQyrVBnb+i+nEg4bsDA+egAAAABJRU5ErkJggg==
Subject Re: trying to call onclick with document.getElement() - document.getElement() returns null
Newsgroups comp.lang.javascript
References <17650677-77bd-4bca-8e10-ed45772f2e9f@googlegroups.com> <87fvyv1r7q.fsf@gmail.com>
MIME-Version 1.0
Lines 110
NNTP-Posting-Date 13 Apr 2013 10:29:50 CEST
NNTP-Posting-Host 470e1d7e.newsspool3.arcor-online.net
X-Trace DXC=Tjb3200RQ3S=>bdbdS?M0YMcF=Q^Z^V3X4Fo<]lROoRQ8kF<OcfhCO[Q^kYTE\6d>QDZm8W4\YJN\b@mF9jNikdUIQbgJMhLo0WY=o9AA<hM;P
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:19250

Show key headers only | View raw


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.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web