473,385 Members | 1,727 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

still hoping for a little help!

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>
Jun 27 '08 #1
15 952
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.
The simplest way to find out is to add alerts throught. That shows the
path the code is taking, and if you alert the values of things too,
it'll show you why. Example:

function getNextPage(){
var num = Math.random();
alert("in getNextPage, random num="+num);
if (num<.5) {
alert("in getNextPage, following<.5 logic")
location.href="group1/group1-lab1.htm";
} else {
alert("in getNextPage, following else logic")
location.href="group2/group2-lab1.htm";
}
}
Jun 27 '08 #2
On Mon, 05 May 2008 11:47:59 +0200, Stevo <no@mail.invalidwrote:
>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.

The simplest way to find out is to add alerts throught. That shows the
path the code is taking, and if you alert the values of things too,
it'll show you why. Example:

function getNextPage(){
var num = Math.random();
alert("in getNextPage, random num="+num);
if (num<.5) {
alert("in getNextPage, following<.5 logic")
location.href="group1/group1-lab1.htm";
} else {
alert("in getNextPage, following else logic")
location.href="group2/group2-lab1.htm";
}
}
Thanks Stevo, I have tried your code but still not clear why my code
isn't working!

After

alert("in getNextPage, following<.5 logic")

I just see the original email address input and not

group1/group1-lab1.htm

Where next?!

Cheers

Geoff
Jun 27 '08 #3
On Mon, 05 May 2008 11:23:38 +0100, Geoff Cox <gc**@freeuk.notcom>
wrote:

re

function getNextPage(){
var num = Math.random();
alert("in getNextPage, random num="+num);
if (num<.5) {
alert("in getNextPage, following<.5 logic")
location.href="group1/group1-lab1.htm";
} else {
alert("in getNextPage, following else logic")
location.href="group2/group2-lab1.htm";
}
}

I should have written that after seeing either

alert("in getNextPage, following<.5 logic")

or

alert("in getNextPage, following else logic")

I just get the original page back - no move to the new page?!

Cheers

Geoff

Jun 27 '08 #4
On Mon, 05 May 2008 11:47:59 +0200, Stevo <no@mail.invalidwrote:
>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.

The simplest way to find out is to add alerts throught. That shows the
path the code is taking, and if you alert the values of things too,
it'll show you why. Example:

function getNextPage(){
var num = Math.random();
alert("in getNextPage, random num="+num);
if (num<.5) {
alert("in getNextPage, following<.5 logic")
location.href="group1/group1-lab1.htm";
} else {
alert("in getNextPage, following else logic")
location.href="group2/group2-lab1.htm";
}
}

Stevo,

I seems that the

location.href="group1/group1-lab1.htm";

or the

location.href="group2group2lab1.htm";

is wrong - but they seem Ok to me ...?

Cheers

Geofg
Jun 27 '08 #5
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
/ \
Jun 27 '08 #6
On Mon, 05 May 2008 15:05:43 +0200, Matthias Watermann <li***@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();
}

}

Jun 27 '08 #7
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@4.67 or 1@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
/ \
Jun 27 '08 #8
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
Jun 27 '08 #9
On Mon, 05 May 2008 17:35:06 +0200, Janwillem Borleffs
<jw@jwscripts.comwrote:
>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
Jun 27 '08 #10
VK
On May 5, 12:04 pm, Geoff Cox <g...@freeuk.notcomwrote:
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

Jun 27 '08 #11
On Mon, 05 May 2008 17:29:52 +0200, Matthias Watermann <li***@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@4.67 or 1@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.
Jun 27 '08 #12
On Mon, 5 May 2008 14:33:29 -0700 (PDT), VK <sc**********@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
Jun 27 '08 #13
On Mon, 05 May 2008 17:29:52 +0200, Matthias Watermann <li***@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@4.67 or 1@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.
Jun 27 '08 #14
On Mon, 05 May 2008 09:04:46 +0100, Geoff Cox <gc**@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>
Try to replace type="submit" with type="button" and call validateEmail
in onclick event.

NNN

Jun 27 '08 #15
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
Jun 27 '08 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rmn | last post by:
Hi, I'm looking for the translation betwen the color spaces, but I must be mistaken with the methods to use, losing the values. Please, I need a little help of a "coloured guru"....
1
by: Chuck Amadi | last post by:
A little help has anyone used the email-dir.py Email Module ,I have downloaded the example and would like some pointers to get it going . For example Have I got to add any parameters to python...
2
by: Rech | last post by:
Hi, I need a little help here managing child processes in Python. I'm not so skilled in system programming so I hope you can give me some good suggestions. I have a very CPU and memory...
2
by: OZ | last post by:
Hi, I am new C++ and need a little help with a public domain program that is suppose to perform a byte swap. I am receiving the following error messages during the compile process with Microsoft...
2
by: | last post by:
Hi, Im kindof new to c++... need a little help with system() function.. I use system to execute a dos program... but i want the rest of the program to continue imediately after executing it. and...
3
by: angeldeveloper | last post by:
Hey guys , is there anybody who can give me a program to this problem. 1. Write a program to create a file called grades.dat. Each line of the file should contain a last name and four scores. Use...
4
by: sandyw | last post by:
I need a little help here with extends. I have three class 1. EventsClass 2. TicketClass I have the extends to EventsClass 3. BuyerClass. I have the extends to EventsClass All three class...
1
by: crashonyou | last post by:
hello..would just like to ask a little help here regarding printing pdf files..i am currently making an automated system for printing files and i have encountered an interesting problem..i already...
1
by: Voxus | last post by:
(This is for C++ guys not C) Hi, I’m a new user and I haven't paid any attention to setting my details, as I am just here to get a little help on programming a small project I’m working on. I...
1
by: Vitalization | last post by:
hey all so i downloaded and installed a script from http://www.mikesworld.net. it works fine on my test website and all but i need a little help. This is how it works: You type in your e-mail...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.