Path: csiph.com!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!nzpost2.xs4all.net!not-for-mail Newsgroups: comp.lang.javascript Subject: Re: form sending undefined From: "Evertjan." References: <69ednX2-9KdxNODFnZ2dnUU7-cPNnZ2d@westnet.com.au> Date: Tue, 17 Jan 2017 15:29:44 +0100 Message-ID: User-Agent: Xnews/2009.05.01 Lines: 51 NNTP-Posting-Host: 77.174.145.5 X-Trace: 1484663381 dreader37.news.xs4all.nl 16729 ehannivo/77.174.145.5:53068 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.javascript:32190 Andrew Poulos wrote on 17 Jan 2017 in comp.lang.javascript: > I have a simple form with two input fields (one of type email and the > other a text area) and when users select Submit I do a simple check to > make sure that both fields have been filled in. For the email field: > > val = h.elements['email'].value.replace(/\s/g,""); > > if (val == "") { > err = "You need to include your email."; >} > > And on modern browsers the email field is self validates. > > In all the testing I've done on multiple browsers in multiple > environments it works as expected but about 5% of the emails it > generates have the value > undefined > for both inputs. > > How do the values become undefined? They could be empty, but not undefined, unless you made some mistake in the code not shown. regex replace() and then compare to ""? Why not use regex test()? try [tested]:
-- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)