Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #10416

Re: read get variables and show/hide div

From Jeff North <jnorthau@yahoo.com.au>
Newsgroups comp.lang.javascript
Subject Re: read get variables and show/hide div
Date 2012-01-20 18:13 +1100
Organization A noiseless patient Spider
Message-ID <ba2ih7lkpg7ee01e5dtu79puq9o2hfscom@4ax.com> (permalink)
References <33182896-a3fa-463b-8bd0-bb14a17e962b@4g2000pbz.googlegroups.com> <t77hh7lcrk9c38ajbt7f295fi0vc99ftv3@4ax.com> <423fce4d-72bc-442d-bd22-8d5b90459545@iu7g2000pbc.googlegroups.com>

Show all headers | View raw


On Thu, 19 Jan 2012 15:32:59 -0800 (PST), in comp.lang.javascript cerr
<ron.eggler@gmail.com>
<423fce4d-72bc-442d-bd22-8d5b90459545@iu7g2000pbc.googlegroups.com>
wrote:

>| On Jan 19, 2:57 pm, Jeff North <jnort...@yahoo.com.au> wrote:
>| > On Thu, 19 Jan 2012 14:17:44 -0800 (PST), in comp.lang.javascript cerr
>| > <ron.egg...@gmail.com>
>| > <33182896-a3fa-463b-8bd0-bb14a17e9...@4g2000pbz.googlegroups.com>
>| > 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%3A%2F%2Fpizzalita.com%2Findex1...
>| 
>| 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. 
 
>| Thank you!
>| Again, the URL:
>|  http://pizzalita.com/index1.html?email=jkhkljh

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();

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

read get variables and show/hide div cerr <ron.eggler@gmail.com> - 2012-01-19 14:17 -0800
  Re: read get variables and show/hide div Jeff North <jnorthau@yahoo.com.au> - 2012-01-20 09:57 +1100
    Re: read get variables and show/hide div cerr <ron.eggler@gmail.com> - 2012-01-19 15:32 -0800
      Re: read get variables and show/hide div Jeff North <jnorthau@yahoo.com.au> - 2012-01-20 18:13 +1100
        Re: read get variables and show/hide div Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-01-21 22:17 +0100

csiph-web