PC Review


Reply
Thread Tools Rate Thread

Can somebody help with this javascript please ?

 
 
=?Utf-8?B?Um9vcGE=?=
Guest
Posts: n/a
 
      27th Jan 2006
Hi all

I am not so good at javascript. Can anybody tell me debug this ?

This is a program which calls otherpage with a variable and the layer div1
should be hidden or shown depending on the variable I am sending across to
the otherpage.htm

firstpage.htm
==========

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>first page</title>
</head>

<body>
<a href="otherpage.htm?vis=yes">Get other page</a>
</body>

</html>



Otherpage.htm
===========

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>otherpage</title>
<script language="JavaScript"><!--
var vis = qsobj(0)
var param = 'div1';

function qsobj(parm)
{
var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=")
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null
}

function disappear(param)
{
document.getElementById(param).style.visibility = 'hidden';
// param.style.visibility="hidden";
}

function reappear()
{
document.getElementById(param).style.visibility = 'visible';
//param.style.visibility="visible";
}

if (vis == 'yes'){
reappear('div1')
}
else {
disappear('div1')
}

//--></script>
</head>

<body>
Hello
<div style="position: absolute; width: 100px; height: 34px; z-index: 1;
left: 11px; top: 60px; visibility:hidden" id="div1">
Hidden layer</div>
</body>

</html>



Thanks,
 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      27th Jan 2006
> I am not so good at javascript. Can anybody tell me debug this ?

debug this.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Roopa" <(E-Mail Removed)> wrote in message
news:1A6DFB1D-2564-46D8-8B59-(E-Mail Removed)...
> Hi all
>
> I am not so good at javascript. Can anybody tell me debug this ?
>
> This is a program which calls otherpage with a variable and the layer div1
> should be hidden or shown depending on the variable I am sending across to
> the otherpage.htm
>
> firstpage.htm
> ==========
>
> <html>
>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>first page</title>
> </head>
>
> <body>
> <a href="otherpage.htm?vis=yes">Get other page</a>
> </body>
>
> </html>
>
>
>
> Otherpage.htm
> ===========
>
> <html>
>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>otherpage</title>
> <script language="JavaScript"><!--
> var vis = qsobj(0)
> var param = 'div1';
>
> function qsobj(parm)
> {
> var qpairs = document.location.search.substring(1).split("&")
> var qvbl = qpairs[parm].split("=")
> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null
> }
>
> function disappear(param)
> {
> document.getElementById(param).style.visibility = 'hidden';
> // param.style.visibility="hidden";
> }
>
> function reappear()
> {
> document.getElementById(param).style.visibility = 'visible';
> //param.style.visibility="visible";
> }
>
> if (vis == 'yes'){
> reappear('div1')
> }
> else {
> disappear('div1')
> }
>
> //--></script>
> </head>
>
> <body>
> Hello
> <div style="position: absolute; width: 100px; height: 34px; z-index: 1;
> left: 11px; top: 60px; visibility:hidden" id="div1">
> Hidden layer</div>
> </body>
>
> </html>
>
>
>
> Thanks,



 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      27th Jan 2006
You had a few problems. The biggest one was that you were running a script
in the head of the document that referred to elements in the body. When the
document loads, the elements in the body are not loaded when the script
runs. I moved the "on load" script to a position below the element it
references.

Read the code to see the other errors I corrected.

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>otherpage</title>
<script language="JavaScript"><!--
var vis = qsobj(0)
var param = 'div1';

function qsobj(parm)
{
var qpairs = document.location.search.substring(1).split("&")
var qvbl = qpairs[parm].split("=");
return qvbl[1] == "yes" ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null
}

function disappear(param)
{
document.getElementById(param).style.visibility = 'hidden';
}

function reappear()
{
document.getElementById(param).style.visibility = 'visible';
}
//--></script>
</head>

<body>
Hello
<div style="position: absolute; width: 100px; height: 34px; z-index: 1;
left: 11px; top: 60px; visibility:hidden" id="div1">
Hidden layer</div>
<script type="text/javascript"><!--
if (vis == 'yes') reappear('div1');
else disappear('div1');
// --></script>
</body>

</html>

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Roopa" <(E-Mail Removed)> wrote in message
news:1A6DFB1D-2564-46D8-8B59-(E-Mail Removed)...
> Hi all
>
> I am not so good at javascript. Can anybody tell me debug this ?
>
> This is a program which calls otherpage with a variable and the layer div1
> should be hidden or shown depending on the variable I am sending across to
> the otherpage.htm
>
> firstpage.htm
> ==========
>
> <html>
>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>first page</title>
> </head>
>
> <body>
> <a href="otherpage.htm?vis=yes">Get other page</a>
> </body>
>
> </html>
>
>
>
> Otherpage.htm
> ===========
>
> <html>
>
> <head>
> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
> <title>otherpage</title>
> <script language="JavaScript"><!--
> var vis = qsobj(0)
> var param = 'div1';
>
> function qsobj(parm)
> {
> var qpairs = document.location.search.substring(1).split("&")
> var qvbl = qpairs[parm].split("=")
> return qvbl[1] ? unescape(qvbl[1].replace(/%20|\+/g," ")) : null
> }
>
> function disappear(param)
> {
> document.getElementById(param).style.visibility = 'hidden';
> // param.style.visibility="hidden";
> }
>
> function reappear()
> {
> document.getElementById(param).style.visibility = 'visible';
> //param.style.visibility="visible";
> }
>
> if (vis == 'yes'){
> reappear('div1')
> }
> else {
> disappear('div1')
> }
>
> //--></script>
> </head>
>
> <body>
> Hello
> <div style="position: absolute; width: 100px; height: 34px; z-index: 1;
> left: 11px; top: 60px; visibility:hidden" id="div1">
> Hidden layer</div>
> </body>
>
> </html>
>
>
>
> Thanks,



 
Reply With Quote
 
Trevor L.
Guest
Posts: n/a
 
      28th Jan 2006
Another way to write the [dis]appear function is
function appear(param)
{
e = document.getElementById(param).style
e.visibility = (e.visibility != 'visible') ? 'visible' : 'hidden
}

You then only have to call the one function:
<script type="text/javascript">appear('div1')</script>

Not tested but I use a similar function (which works) and I copied it from
that.

--
Cheers,
Trevor L.
Website: http://tandcl.homemail.com.au


 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      29th Jan 2006
Hi Trevor,

True, but I didn't want to make assumptions about his requirements. I also
noted to myself that a single function which took a boolean parameter would
have worked, but if he was planning on extending these functions to do more,
I shouldn't have made the assumption that he needed a single function. So I
didn't!

Anyway, that's my story, and I'm stickin' to it! ;-)

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Trevor L." <Trevor L.@Canberra> wrote in message
news:(E-Mail Removed)...
> Another way to write the [dis]appear function is
> function appear(param)
> {
> e = document.getElementById(param).style
> e.visibility = (e.visibility != 'visible') ? 'visible' : 'hidden
> }
>
> You then only have to call the one function:
> <script type="text/javascript">appear('div1')</script>
>
> Not tested but I use a similar function (which works) and I copied it from
> that.
>
> --
> Cheers,
> Trevor L.
> Website: http://tandcl.homemail.com.au
>



 
Reply With Quote
 
=?Utf-8?B?Um9vcGE=?=
Guest
Posts: n/a
 
      30th Jan 2006
Thanks Kevin and Trevor. Your inputs were really helpful.

"Kevin Spencer" wrote:

> Hi Trevor,
>
> True, but I didn't want to make assumptions about his requirements. I also
> noted to myself that a single function which took a boolean parameter would
> have worked, but if he was planning on extending these functions to do more,
> I shouldn't have made the assumption that he needed a single function. So I
> didn't!
>
> Anyway, that's my story, and I'm stickin' to it! ;-)
>
> --
> HTH,
>
> Kevin Spencer
> Microsoft MVP
> ..Net Developer
> Who is Mighty Abbott?
> A twin turret scalawag.
>
> "Trevor L." <Trevor L.@Canberra> wrote in message
> news:(E-Mail Removed)...
> > Another way to write the [dis]appear function is
> > function appear(param)
> > {
> > e = document.getElementById(param).style
> > e.visibility = (e.visibility != 'visible') ? 'visible' : 'hidden
> > }
> >
> > You then only have to call the one function:
> > <script type="text/javascript">appear('div1')</script>
> >
> > Not tested but I use a similar function (which works) and I copied it from
> > that.
> >
> > --
> > Cheers,
> > Trevor L.
> > Website: http://tandcl.homemail.com.au
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Generated JavaScript vs. Manually Created JavaScript: Which one comes first? Nathan Sokalski Microsoft ASP .NET 4 8th Nov 2007 07:24 AM
C# and javascript? Or C# and Javascript + IE?! I really dont know... porter Microsoft C# .NET 1 5th Oct 2007 08:31 PM
How to fire Javascript events from a .NET winforms user control back to Javascript in IE jonathan.beckett Microsoft Dot NET 0 13th Jul 2006 02:51 PM
application/x-javascript vs. text/javascript. Peter Rilling Microsoft ASP .NET 1 14th Mar 2004 03:41 PM
Javascript:void(null); or Javascript:; -problem clicking certain js action items chribjor Windows XP Internet Explorer 1 21st Jan 2004 11:57 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:19 PM.