Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #32190
| Newsgroups | comp.lang.javascript |
|---|---|
| Subject | Re: form sending undefined |
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
| References | <69ednX2-9KdxNODFnZ2dnUU7-cPNnZ2d@westnet.com.au> |
| Date | 2017-01-17 15:29 +0100 |
| Message-ID | <XnsA7009DA1AF7ADeejj99@194.109.6.166> (permalink) |
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
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