read get variables and show/hide div

C

cerr

Hi,

I want to display a div but only if no GET variable "email" is
present.
And I would like to hide my div when someone hits a specific button.
So far I have come up with this:
http://pizzalita.com/index1.html?email=MyEmail

There's that div in the middle (shat should not show because there's
email in GET) and when someone clicks the cross, it should
disappear.... but I don't get it working correctly.
Some help would be gladly appreciated!
Thank you very much!!!

Ron
 
J

Jeff North

On Thu, 19 Jan 2012 14:17:44 -0800 (PST), in comp.lang.javascript cerr
<[email protected]>
| Hi,
|
| I want to display a div but only if no GET variable "email" is
| present.
| And I would like to hide my div when someone hits a specific button.
| So far I have come up with this:
| http://pizzalita.com/index1.html?email=MyEmail
|
| There's that div in the middle (shat should not show because there's
| email in GET) and when someone clicks the cross, it should
| disappear.... but I don't get it working correctly.
| Some help would be gladly appreciated!
| Thank you very much!!!
|
| Ron
If you get rid of the error on the page you might find out why it
isn't working i.e line 290

http://validator.w3.org/check?uri=h...(detect+automatically)&doctype=Inline&group=0
 
C

cerr

@gmail.com>


If you get rid of the error on the page you might find out why it
isn't working i.e line 290

http://validator.w3.org/check?uri=http://pizzalita.com/index1....

Yep, thank you, got it partly going (had to use GetElemenById instead
of GetElementsByName) but I'm still not able to retrieve the GET
variable.
I got the Regular expression and the $_GET() function from
http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/
Can you - or anyone else for that matter - see what is wrong?

Thank you!
Again, the URL:
http://pizzalita.com/index1.html?email=jkhkljh
 
J

Jeff North

On Thu, 19 Jan 2012 15:32:59 -0800 (PST), in comp.lang.javascript cerr
<[email protected]>
| > On Thu, 19 Jan 2012 14:17:44 -0800 (PST), in comp.lang.javascript cerr
| > <[email protected]>
| > <[email protected]>
| > wrote:
| >
| > >| Hi,
| > >|
| > >| I want to display a div but only if no GET variable "email" is
| > >| present.
| > >| And I would like to hide my div when someone hits a specific button.
| > >| So far I have come up with this:
| > >|http://pizzalita.com/index1.html?email=MyEmail
| > >|
| > >| There's that div in the middle (shat should not show because there's
| > >| email in GET) and when someone clicks the cross, it should
| > >| disappear.... but I don't get it working correctly.
| > >| Some help would be gladly appreciated!
| > >| Thank you very much!!!
| > >|
| > >| Ron
| >
| > If you get rid of the error on the page you might find out why it
| > isn't working i.e line 290
| >
| > http://validator.w3.org/check?uri=http://pizzalita.com/index1...
|
| Yep, thank you, got it partly going (had to use GetElemenById instead
| of GetElementsByName) but I'm still not able to retrieve the GET
| variable.
| I got the Regular expression and the $_GET() function from
| http://www.onlineaspect.com/2009/06/10/reading-get-variables-with-javascript/
| Can you - or anyone else for that matter - see what is wrong?

The $_GET function is throwing an error which in turn prevents all the
other scripts from running. Try replacing the current $_GET function
with
function $_GET(q,s) {
var res = new Array();
s = (s != null) ? s : window.location.search;
var re = new RegExp("("+q+"[ |=])(.*?)(?=&|$)","i");
var result = s.match(re);
return (result == null ) ? '' : result[2];
}

Another problem is that you are not calling the $_GET function so
there is no-way that it is going to be executed. You need to add:
if( $_GET('email') != '' ) closediv();
just after the $_GET function.

The previous RegExp and this RegExp does *not* check if the email
address is well-formed. Thus the above example would hide the emaildiv
'window'.

If you want to check that there is a well-formed email address then
replace the $_GET function with the following (delete the line 'if(
$_GET('email') != '' ) closediv();' also:
function $_GET(q,s) {
var res = new Array();
s = (s != null) ? s : window.location.search;
var re = new RegExp("("+q+"[ |=])(.*?)(?=&|$)","i");
var result = s.match(re);
return (result == null ) ? '' : result[2];
}
function checkEmail(email) {
var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i;
var x = email.match(re);
return( x == null ) ? false : true;
}
if( checkEmail( $_GET('email') ) == true ) closediv();
 
T

Thomas 'PointedEars' Lahn

Jeff said:
The $_GET function is throwing an error which in turn prevents all the
other scripts from running. Try replacing the current $_GET function
with
function $_GET(q,s) {
var res = new Array();
s = (s != null) ? s : window.location.search;
var re = new RegExp("("+q+"[ |=])(.*?)(?=&|$)","i");
var result = s.match(re);
return (result == null ) ? '' : result[2];
}

Another problem is that you are not calling the $_GET function so
there is no-way that it is going to be executed. You need to add:
if( $_GET('email') != '' ) closediv();
just after the $_GET function.

Potentially confusing and harder-to-maintain results of such identifier
abuse were probably one reason why ECMAScript Edition 3 contained a note
that identifiers starting with `$' should be machine-generated.

Please do not do that.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top