Solved

Pass JS variable in query string

Posted on 2009-03-30
17
334 Views
Last Modified: 2012-05-06
I have few divs and images on a page. Clicking on any image shows the respective div and hide other. This is being done through js function. By default div one is open. Now if my visitor is on div 3 , I would like to have an image clicking on that image should refresh the page with div 3 open. I also want to auto refresh page after 3 minutes opening same div on which user is.

I am using PHP and javascript.
function togLayer(id) 
{ 
if(currLayerId) setDisplay(currLayerId, "none"); 
if(id) setDisplay(id, "block"); 
 
imgid = 'img' + id;
var imgelm = document.getElementById(imgid);
var previmg = document.getElementById(previmgid);
 
 
if (previmgid == imgid)
	{
	
		imgelm.src='images/open_' + id + 'over.jpg';
		imgbool=id;
	}
else
	{
	
		imgelm.src='images/open_' + id + 'over.jpg';
		subid = previmgid.substring(3,15);
		previmg.src='images/open_' + subid + '.jpg';
		imgbool=id;
	}
 
 
currLayerId = id; 
previmgid = imgid;
}

Open in new window

0
Comment
Question by:Naveed_Manzoor
  • 7
  • 7
  • 3
17 Comments
 
LVL 22

Expert Comment

by:neeraj523
ID: 24017009

save current open div id in cookies and keep on updating this cookie everytime user switched slide.. On refresh, check for this cookie value and show current slide..

note: keep cookie expiry at the end of session..
0
 

Author Comment

by:Naveed_Manzoor
ID: 24017103
Can I not pass js var in query string  ?
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 24017275

you can but that will attract lot of changes to the code and everytime, you will have to preserve that variable..
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 

Author Comment

by:Naveed_Manzoor
ID: 24017435
can you provide me cookie setter and reader code ?
0
 
LVL 22

Expert Comment

by:neeraj523
ID: 24017721
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24018298
Use the hash

location.hash="#div3"
0
 

Author Comment

by:Naveed_Manzoor
ID: 24026545
mplungjan
can you please provide me details of using hash
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24026587
0
 

Author Comment

by:Naveed_Manzoor
ID: 24027018
i have hash for all my links. Now I need a button that refresh the same page with hash of the page. That's what am trying to do .
<A HREF="openqportal.php getLocationHash()"><img src="images/iconRefresh.jpg" alt="" name="Refresh" width="28" height="38" border="0" id="Refresh"  /></a>

how can I concatenate hash value with page name ???
I want to makew this link .... penqportal.php#bus
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24027121
You mean
<A HREF="openqportal.php" onClick="location.hash='#bus'; return false"><img src="images/iconRefresh.jpg" alt="" name="Refresh" width="28" height="38" border="0" id="Refresh"  /></a>

or just

<A HREF="#bus"><img src="images/iconRefresh.jpg" alt="" name="Refresh" width="28" height="38" border="0" id="Refresh"  /></a>
if you are already in the page or
 
<A HREF="openqportal.php#bus"><img src="images/iconRefresh.jpg" alt="" name="Refresh" width="28" height="38" border="0" id="Refresh"  /></a>

if you are in another page

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24027124
If you need to actually LOAD the page again, then that is something else
0
 

Author Comment

by:Naveed_Manzoor
ID: 24035914
I am on same page but need to reload the page with hash value like
<A HREF="openqportal.php#bus">
<A HREF="openqportal.php#med">

This med and bus I have to get from url. Function for getting hash is getLocationHash() (I am using). Now I have to form a url like pagename + hash value  <A HREF="openqportal.php#med">.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24036427
so
<A HREF="openqportal.php" onClick="location.replace(this.href+getLocationHash()); return false"><img src="images/iconRefresh.jpg" alt="" name="Refresh" width="28" height="38" border="0" id="Refresh"  /></a>

0
 

Author Comment

by:Naveed_Manzoor
ID: 24036585
This is not working. Its doing nothing. I need te reload the page too
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 24036611
That is sort of defeating the point of using HASH, then just use query string

But if you need, try this

<A HREF="openqportal.php" onClick="location.hash=getLocationHash(); location.reload(1); return false"><img src="images/iconRefresh.jpg" alt="" name="Refresh" width="28" height="38" border="0" id="Refresh"  /></a>

0
 

Accepted Solution

by:
Naveed_Manzoor earned 0 total points
ID: 25378734
This didnt work . I need to close it now.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 25380428
So close it
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can i get the length? 7 32
https://github.com/willowsystems/jSignature 11 50
Jquery GMAP3 Hierarchy 1 27
Button and js nou working 3 7
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question