From: Matthias Watermann on
On Mon, 05 May 2008 09:04:46 +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
/"\
\ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
X - AGAINST M$ ATTACHMENTS
/ \
From: Geoff Cox on
On Mon, 05 May 2008 15:05:43 +0200, Matthias Watermann <lists(a)mwat.de>
wrote:

>On Mon, 05 May 2008 09:04:46 +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.

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?

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 CheckEmail(email) {

AtPos = email.indexOf("@");
StopPos = email.lastIndexOf(".");

if (email == "") {
alert('Not a valid Email address');
}

if (AtPos == -1 || StopPos == -1) {
alert('Not a valid email address');
}

if (StopPos < AtPos) {
alert('Not a valid email address');
}

if (StopPos - AtPos == 1) {
alert('Not a valid email address"');
}

document.emailForm.email_address.focus();
document.emailForm.email_address.select();

if (email != "" && (AtPos != -1 || StopPos != -1) && StopPos > AtPos
&& StopPos - AtPos != 1) {
parent.frame_top.top_value = email;
getNextPage();
}

}

From: Thomas 'PointedEars' Lahn on
Janwillem Borleffs wrote:
> Geoff Cox schreef:
>> 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;
> }

This will fail in 51% of cases.

Read and apply http://www.mnot.net/cache_docs/ instead.


PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
From: Matthias Watermann on
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.

> 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.


--
Matthias
/"\
\ / ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
X - AGAINST M$ ATTACHMENTS
/ \
From: Janwillem Borleffs on
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