Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <2191909.4EKZz3fc86@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Mon, 03 Dec 2012 23:15:40 +0100 User-Agent: KNode/4.4.11 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+&. Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 51 NNTP-Posting-Date: 03 Dec 2012 23:15:42 CET NNTP-Posting-Host: b5e16711.newsspool1.arcor-online.net X-Trace: DXC=`3dbeR8[k On 4/12/2012 8:04 AM, justaguy wrote: >> Here's a simple js function. >> >> // detect if any of 4 fields is empty before data entry in field 5 >> function haveFour() { >> var fourFields = ['rep','contact','Market_Segment','pricing']; >> for (i=0; i<4; i++) { >> if (document.getElementById(fourFields[i]).value=='') { >> alert('Please fill in '+fourFields[i] + ' field'); >> return; >> } >> } >> } >> >> However, it works as designed for Chrome 23, Firefox 16 >> but it fails with IE9. All on Windows 7. >> Any idea as to the reason of failing IE9? > > What about testing for > if (!document.getElementById(fourFields[i]).value.length) { > instead? That would be unnecessarily cryptic, error-prone and comparably inefficient on top of the already inefficient approach. > Also I'd put 'i' in with 'var' ie > var i, fourFields... > and add > var len = fourFields.length; > for (i = 0; i < len; i++) { Or var fourFields = …; for (var i = 0, len = fourFields.length; i < len; i++) { > We need to see the HTML to know what might be going awry. More important, we need to know their definition of an "empty field" and "fails". PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee