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


Groups > comp.lang.javascript > #32190

Re: form sending undefined

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." <exxjxw.hannivoort@inter.nl.net>
References <69ednX2-9KdxNODFnZ2dnUU7-cPNnZ2d@westnet.com.au>
Date Tue, 17 Jan 2017 15:29:44 +0100
Message-ID <XnsA7009DA1AF7ADeejj99@194.109.6.166> (permalink)
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

Show key headers only | View raw


Andrew Poulos <ap_prog@hotmail.com> 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]:

<form onsubmit = 'return testForm(this)'>
	<input type='email' name='myEmail'>
	<input type='text' name='myText'>
	<input type='submit'>
</form>

<script type='text/javascript'> 'use strict'
function testForm(t) {
    	var okE = /[^\s]/.test(t.elements['myEmail'].value);
    	var okT = /[^\s]/.test(t.elements['myText'].value);
    	if (!okE) alert("You need to include your email-ADDRESS");
    	if (!okT) alert("You need to give some text");
    	return okE && okT;
};
</script>

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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


Thread

form sending undefined Andrew Poulos <ap_prog@hotmail.com> - 2017-01-17 16:21 +1100
  Re: form sending undefined JJ <jj4public@vfemail.net> - 2017-01-17 15:15 +0700
  Re: form sending undefined "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2017-01-17 15:29 +0100
  Re: form sending undefined Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-17 16:16 +0100
    Re: form sending undefined Andrew Poulos <ap_prog@hotmail.com> - 2017-01-19 12:13 +1100
      Re: form sending undefined Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-01-19 18:19 +0100
        Re: form sending undefined Andrew Poulos <ap_prog@hotmail.com> - 2017-01-20 07:28 +1100

csiph-web