From: Geoff Cox on
On Mon, 05 May 2008 17:35:06 +0200, Janwillem Borleffs
<jw(a)jwscripts.com> wrote:

>Geoff Cox schreef:
>> Hello
>>
>> I cannot see why this is not working - the idea being to check the
>> email address entered and if OK to move to either one of 2 pages - the
>> move does not happen.
>>
>> The code below is in the lower of 2 frames.
>>
>
>Perhaps browser caching is your problem, try the following:
>
>if (num<.5) {
> location.href="group1/group1-lab1.htm?" + num;
>} else {
> location.href="group2/group2-lab1.htm?" + num;
>}
>
>
>JW

tried the above - no change!

Cheers

Geoff
From: VK on
On May 5, 12:04 pm, Geoff Cox <g...(a)freeuk.notcom> wrote:
> Hello
>
> I cannot see why this is not working - the idea being to check the
> email address entered and if OK to move to either one of 2 pages - the
> move does not happen.
>
> The code below is in the lower of 2 frames.
>
> Why?!
>
> Cheers
>
> Geoff
>
> function getNextPage(){
> var num = Math.random();
> if (num<.5) {
> location.href="group1/group1-lab1.htm";
> } else {
> location.href="group2/group2-lab1.htm";
> }
>
> }
>
> function validateEmail ( emailField, errorMsg ) {
> emailpat =
> /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
> if( !emailpat.test( emailField.value ) ) {
> alert( errorMsg);
> emailField.focus();
> emailField.select();
> return false;
> } else {
> getNextPage();
> }
>
> }
>
> //-->
> </script>
>
> </head>
>
> <body>
>
> <h2>test</h2>
>
> <form name="emailForm" onsubmit="validateEmail( this.email , 'Please
> enter a valid email address')">
> Please enter your email address <input type="text" name="email">
> <input type="submit" value="enter">
> </form>

in case of a valid e-mail the flow goes to getNextPage

getNextPage sets location.href and exits without return value

onsubmit treats it as "OK to submit" and submits the form

action attribute if your form is not sets which defaults to
action="current URL" so the page gets reloaded

on page reload script gets reloaded as well so whatever location
change are made being lost

-------------------------------

make you getNextPage return false as well

From: Geoff Cox on
On Mon, 05 May 2008 17:29:52 +0200, Matthias Watermann <lists(a)mwat.de>
wrote:

>On Mon, 05 May 2008 14:45:37 +0100, Geoff Cox wrote:
>
>> [...]
>>>> I cannot see why this is not working - the idea being to check the
>>>> email address entered and if OK to move to either one of 2 pages - the
>>>> move does not happen.
>>>> [...]
>>>> function getNextPage(){
>>>> var num = Math.random();
>>>> if (num<.5) {
>>>> location.href="group1/group1-lab1.htm";
>>>> } else {
>>>> location.href="group2/group2-lab1.htm";
>>>> }
>>>> }
>>>
>>>"location.href" is supposed to hold a _complete_ URL but your code
>>>misses at least the protocol and host parts (i.e. "http://www.dom.tld/").
>>>You might try using the "location.pathname" property which would accept
>>>your value. However, that would not cause the browser to change to
>>>that page.
>>
>> Matthias,
>>
>> I've tried the full URL (http:// etc) but no difference.
>
>How do you define "no difference"? Just by (visual appearance)? Or did
>you check the web-server logs to see whether there was a request
>actually? Quite possibly the browser could have requested something
>but failed (for whatever reasons) to update the display. But that's
>just a wild guess.

Here's a clue?!

If I use FF I do not get the move to either of the 2 pages but if I
step through the script with Firebug it works!

Why?

Cheers

Geoff

>
>> Odd thing is that I have another file which uses a different type of
>> check and that works OK - I cannot see the difference - this is it
>> below. can you see the difference which accounts for it working?
>
>Well, no. I'd recommend to create a test page _without_ frames (which
>are an evil of the last century anyway) just to make sure, your
>JavaScript code works at all. Only _after_ you've verified that each
>snippet works as intended/expected include the code in your "real"
>pages.
>
>To check email addresses I'm using a simple RegEx:
>
>var _reMail = /^\s*([\w\x2D\x2E]+\@([\w\x2D]+\x2E)+[A-Za-z]{2,5})/;
>
>This is used by the onchange/onblur event method
>
>function cbMail() {
> if (! this.value) {
> return; // nothing to do
> } // if
> var h = _reMail.exec(this.value);
> // required minimum: 12(a)4.67 or 1(a)34.67
> this.value = ((h) && (h[1]) && (6 < h[1].length)) ? h[1] : '';
>} // cbMail()
>
>which I assign to the respective form field objects. In the form
>object's submit handler then I've to check just whether there's a
>value of not.
From: Geoff Cox on
On Mon, 5 May 2008 14:33:29 -0700 (PDT), VK <schools_ring(a)yahoo.com>
wrote:


>>
>> <body>
>>
>> <h2>test</h2>
>>
>> <form name="emailForm" onsubmit="validateEmail( this.email , 'Please
>> enter a valid email address')">
>> Please enter your email address <input type="text" name="email">
>> <input type="submit" value="enter">
>> </form>
>
>in case of a valid e-mail the flow goes to getNextPage
>
>getNextPage sets location.href and exits without return value
>
>onsubmit treats it as "OK to submit" and submits the form
>
>action attribute if your form is not sets which defaults to
>action="current URL" so the page gets reloaded
>
>on page reload script gets reloaded as well so whatever location
>change are made being lost
>
>-------------------------------
>
>make you getNextPage return false as well

Brilliant!

<form name="emailForm" onsubmit="validateEmail( this.email , 'Please
enter a valid email address');return false;">

The return false gets the next page - thanks for your analysis!

Cheers

Geoff
From: Geoff Cox on
On Mon, 05 May 2008 17:29:52 +0200, Matthias Watermann <lists(a)mwat.de>
wrote:


Matthias,

VK spotted the reason! - the missing return false in

<form name="emailForm" onsubmit="validateEmail( this.email , 'Please
enter a valid email address');return false;">

I'll have a look at your code below now. Thanks for that.

Cheers

Geoff


>To check email addresses I'm using a simple RegEx:
>
>var _reMail = /^\s*([\w\x2D\x2E]+\@([\w\x2D]+\x2E)+[A-Za-z]{2,5})/;
>
>This is used by the onchange/onblur event method
>
>function cbMail() {
> if (! this.value) {
> return; // nothing to do
> } // if
> var h = _reMail.exec(this.value);
> // required minimum: 12(a)4.67 or 1(a)34.67
> this.value = ((h) && (h[1]) && (6 < h[1].length)) ? h[1] : '';
>} // cbMail()
>
>which I assign to the respective form field objects. In the form
>object's submit handler then I've to check just whether there's a
>value of not.