Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pop up windows - random content.

Status
Not open for further replies.

drumin

Technical User
Mar 18, 2001
10
GB
I need to devise a window that automatically pops up when a user enters a specific page but displays content randomly each time they access this page. i.e. first visit it'll have info on Product A, 2nd visit it'll pop up with info on one of the other products.

Any ideas??? I know how to do an automatic pop up but unsure of the random element.
 
My suggestion (although I might be in the wrong forum) would be to use ASP, and store the addresses of the different pages you wish to load in a simple database table. Each time the page is called, it would generate a random number, pluck the address that corresponds to that row number from the table, and display the contents.

If you post that you're interested in some sample code, I'll post some that would do just that. But this being a javascript forum, I'll hold off till you say you'd like to see that.

good luck! :)
Paul Prewett
 
Hi Paul

I would be most interested in the code! Please send it, it does sound like a viable route. My plan was to look into JavaScript initially and if no joy there have a look at an ASP solution.

Many thanks

Philip Reid :)
 
Very good then... We'll assume here for simplicity's sake that you have a 10 row table with one field called "address", which (strangely enough) would contain the addresses of the 10 different pages that would hold the content that you wished to display.

I'll also assume you know how to connect to the database and get your 10 record recordset and already have that in a recordset called 'rs'... (if you don't, post, and i'll put more detailed code up)

Here goes:
Code:
<%
dim upperLimit, lowerLimit, randNum
upperlimit = 10
lowerlimit = 1
Int((upperlimit - lowerlimit + 1)*Rnd() + lowerlimit)
'line above generates the desired random number between 1 and 10

rs.move(randNum)

response.redirect(rs(&quot;address&quot;))
%>

So, you get your random number, find the corresponding entry, and then just move the window to that location. Be sure that the page you write all that code above on is void of any html headers. If you do that, then the page, itself, will be completely transparent to the visitor, and the resulting page will pop up nearly instantaneously (assuming there are no problems connecting to the database). I would go one step further if there are a relatively small number of pages (like the above example) and say that you might even want to just populate an array with the addresses and use that as your index. That would avoid any potential connectivity issues, but if the information changes alot, or there are a large number of possiblities, then I would suggest going the db route.

hope it helps! :) Let me know how it works out.
Paul Prewett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top