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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hide button after it is clicked

Status
Not open for further replies.

acewilli

IS-IT--Management
Apr 11, 2003
98
US
Hello, how can I hide a button after it is clicked and then unhide it the 1st of each month? The button is a standard form button like below. Thanks in advance!

Code:
	<FORM>
	<INPUT TYPE="BUTTON" VALUE="Random Drawing" ONCLICK="window.location.href='../cssopt/random.asp'"> 
	</FORM>
 
this should be on the client level with a toggle function

if you need to by interacting with some sort of process on the server being the condition that either shows or hides the button you can pass some value to the javascript function in order to show or hide the button also

eg..

var catchIt = "<%=variable%>"
if(catchIt <> "") {
call the function
}

etc...


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
You could put that portion of HTML inside a logic statement in your ASP to say:

<%
If dayofmonth = first Then
%>
Html code here
<%
End If
%>

My example above will NOT work, it just expresses the idea.
You would have to determine the criteria and how to test it.
You may have to have a control file somewhere to indicate if it has already been clicked for that month and update that file when the next click event occurs.


At my age I still learn something new every day, but I forget two others.
 
I have a back-end script that runs at midnight on the 1st of each month to archive the information in the database for that month. I've posted it below and I know it is really long and probably not the best way to do it but it works well and accomplishes the task. Is there any way that I can use this back-end script as the control file? It runs via taskmgr on the windows box.

Code:
Dim db
Dim strserver
Dim strmonthly
Dim stryearly
Dim strday

db2 = "CSSOPT"

strserver = "OICU8121100341A5AAB"

'Create Connection
set db = CreateObject("ADODB.Connection")
strdb = "driver={SQL SERVER};server=" & strserver & ";uid=sa;pwd=password;database=" & db2 & ""
db.Open strdb

'Create Command
set doit = CreateObject("ADODB.Command")
set doit.ActiveConnection = db

	strmonthly=datepart("m",date)
	stryearly=datepart("yyyy",date)
	strday=datepart("d",date)	
	
	If strmonthly="1" then
		strmonthly="January"
	elseif strmonthly="2" then
		strmonthly="February"
	elseif strmonthly="3" then
		strmonthly="March"
	elseif strmonthly="4" then
		strmonthly="April"
	elseif strmonthly="5" then
		strmonthly="May"
	elseif strmonthly="6" then
		strmonthly="June"
	elseif strmonthly="7" then
		strmonthly="July"
	elseif strmonthly="8" then
		strmonthly="August"
	elseif strmonthly="9" then
		strmonthly="September"
	elseif strmonthly="10" then
		strmonthly="October"
	elseif strmonthly="11" then
		strmonthly="November"
	elseif strmonthly="12" then
		strmonthly="December"
	else
	end if	

					db.execute ("UPDATE Team SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team2 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team3 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team4 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team5 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team6 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team7 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team8 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team9 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					db.execute ("UPDATE Team10 SET tpoints='10', yrpoints='0', mopoints='0', npoints='0', memo=''")
					
					db.execute ("UPDATE Home SET ttmopoints='0'")

sql = "Select * FROM Home"
set rs = CreateObject("ADODB.Recordset")
rs.Open sql, db

			For i=1 to 10

				set rty=db.execute ("SELECT SUM(Home.tyrpoints) as strytotal from Home WHERE ID="& i)
				set rty2=db.execute ("SELECT SUM(Home.t2yrpoints) as strytotal2 from Home WHERE ID="& i)
				set rty3=db.execute ("SELECT SUM(Home.t3yrpoints) as strytotal3 from Home WHERE ID="& i)
				set rty4=db.execute ("SELECT SUM(Home.t4yrpoints) as strytotal4 from Home WHERE ID="& i)
				set rty5=db.execute ("SELECT SUM(Home.t5yrpoints) as strytotal5 from Home WHERE ID="& i)
				set rty6=db.execute ("SELECT SUM(Home.t6yrpoints) as strytotal6 from Home WHERE ID="& i)
				set rty7=db.execute ("SELECT SUM(Home.t7yrpoints) as strytotal7 from Home WHERE ID="& i)
				set rty8=db.execute ("SELECT SUM(Home.t8yrpoints) as strytotal8 from Home WHERE ID="& i)
				set rty9=db.execute ("SELECT SUM(Home.t9yrpoints) as strytotal9 from Home WHERE ID="& i)
				set rty10=db.execute ("SELECT SUM(Home.t10yrpoints) as strytotal10 from Home WHERE ID="& i)
				
				set ytp=db.execute ("SELECT SUM(Home.ttyrpts) as stryrtotal from Home WHERE ID="& i)
'				set ytp2=db.execute ("SELECT SUM(Home.tt2yrpts) as stryrtotal2 from Home WHERE ID="& i)
'				set ytp3=db.execute ("SELECT SUM(Home.tt3yrpts) as stryrtotal3 from Home WHERE ID="& i)
'				set ytp4=db.execute ("SELECT SUM(Home.tt4yrpts) as stryrtotal4 from Home WHERE ID="& i)
'				set ytp5=db.execute ("SELECT SUM(Home.tt5yrpts) as stryrtotal5 from Home WHERE ID="& i)
'				set ytp6=db.execute ("SELECT SUM(Home.tt6yrpts) as stryrtotal6 from Home WHERE ID="& i)
'				set ytp7=db.execute ("SELECT SUM(Home.tt7yrpts) as stryrtotal7 from Home WHERE ID="& i)
'				set ytp8=db.execute ("SELECT SUM(Home.tt8yrpts) as stryrtotal8 from Home WHERE ID="& i)																								
'				set ytp9=db.execute ("SELECT SUM(Home.tt9yrpts) as stryrtotal9 from Home WHERE ID="& i)
'				set ytp10=db.execute ("SELECT SUM(Home.tt10yrpts) as stryrtotal10 from Home WHERE ID="& i)

				stryear= rty("strytotal") + rty2("strytotal2") + rty3("strytotal3") + rty4("strytotal4") + rty5("strytotal5") + rty6("strytotal6") + rty7("strytotal7") + rty8("strytotal8") + rty9("strytotal9") + rty10("strytotal10")
				stryr= ytp("stryrtotal")
'+ ytp2("stryrtotal2") + ytp3("stryrtotal3") + ytp4("stryrtotal4") + ytp5("stryrtotal5") + ytp6("stryrtotal6") + ytp7("stryrtotal7") + ytp8("stryrtotal8") + ytp9("stryrtotal9") + ytp10("stryrtotal10")
				stry= stryr + stryear

				strSQL = "UPDATE Home SET ttyrpts='"& stry &"' WHERE ID="& i
				db.Execute strSQL

			Next

					db.execute ("UPDATE Home SET tyrpoints='0', tmopoints='0'")
					db.execute ("UPDATE Home SET t2yrpoints='0', t2mopoints='0'")
					db.execute ("UPDATE Home SET t3yrpoints='0', t3mopoints='0'")
					db.execute ("UPDATE Home SET t4yrpoints='0', t4mopoints='0'")
					db.execute ("UPDATE Home SET t5yrpoints='0', t5mopoints='0'")
					db.execute ("UPDATE Home SET t6yrpoints='0', t6mopoints='0'")
					db.execute ("UPDATE Home SET t7yrpoints='0', t7mopoints='0'")
					db.execute ("UPDATE Home SET t8yrpoints='0', t8mopoints='0'")
					db.execute ("UPDATE Home SET t9yrpoints='0', t9mopoints='0'")
					db.execute ("UPDATE Home SET t10yrpoints='0', t10mopoints='0'")


set con = nothing
set doit = Nothing
 
First off you can get the month "Name" by MonthName(Month(date()))

Second you really need to take into account the dynamic theory. Why? well, the size of your scripts for one. The ease of maintaining them for two. The ease of changing them for three and that ever debugging task.

Third how does this run from the task manager? Did you mean scheduled tasks?

OK. You have quite a bit of string building up there. No, you don't have SQL statements, you only have strings to the ASP script. So I'm really curious why you seemed to have used copy/paste and changed a number in each one when you already have a counter in the strings themselves that appears to be the same number as the static entered one.

e.g.
Code:
SELECT SUM(Home.t2yrpoints) as strytotal2 from Home WHERE ID="& i

how about

Code:
"SELECT SUM(Home.t" & i & "yrpoints) as strytotal" & i & " from Home WHERE ID="& i

for starters....

And what are you talking about? You posted to the effect of hiding a button. What control file? Don't change subjects mid-stream in a thread. Just start a new thread to keep it clean and helpful for everyone

General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Please tell me your sa password isn't really "password"

You should never use sa for any development work. No reasons at all.

General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Sorry...I was referring to theniteowl's comments about using a control file. I should have specified whom I was speaking to. Sorry about that.

Thanks,

acewilli
 
Got it. My bad in that case for not paying attention more to the entire thread


____________ signature below ______________
General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
No...the password isn't password...I changed up everything that was sensitive information. I didn't explain that either. Sorry. I'm not very good at this but I know better than to do something that crazy. ;-)

Thanks,

acewilli
 
Here is how I see it.
You want the button to show after the beginning of each month but only until the first time it is clicked.
So you have to know the current month and the last time the button was clicked to determine if the button should show.

I said control file to keep track of when the last click was but really you could do it other ways. Since you have a database you can store the event data there.

Code:
<%
' Grab number of month button last clicked from DB
lastmonth = VALUE YOU PULLED FROM DATABASE
curmonth = Month(Date) 'This months number

If lastmonth <> curmonth Then
%>
  display your button HTML here
<%
End If
%>

You would either have to have the button act as a submit button to call another page and update the database with the new month or you would use an onclick event on that button and a little javascript to set a hidden form field value with the new month number so when you do go to the next page you can check to see if the value was set and the database needs updating.

If you did not use a database for this application you can use a bit of ASP code to read/write the month from/into a text file in the application folder. You would want to make sure the info is updated when the button pressing event occurs though not just at the end of the month when you backup your database otherwise the button would appear every day until the backup occured.




At my age I still learn something new every day, but I forget two others.
 
onpnt, thank you for straightening me out my use of i. I knew that I had done it wrong and that there was way to many lines of code. You suggestion has helped tremendously. Thank you.

theniteowl, I will see if I can use this. I need to hide the button when it is clicked and then reappear at the 1st of every month and this might do the trick.

One other thing....Suggestions are welcome so if what I'm asking to do doesn't seem like a good way to do it then please give me your opinion on how you think I should do this. The rundown....I need to make it so random people cannot click the button anytime they choose so that when the button is clicked to pick a winner we only have the one person's name and no one can click it again to change the winner. What is the best way in both of your opinion's on how to accomplish this. Apparently the way I am thinking of doing it is not how a seasoned programmer would do it. I am new to ASP/vbscript/jscript so my code is a newbie not someone that has done this forever so I do apologize for how cruddy the code is and thank you for the suggestions.

Thanks again,

acewilli
 
I'm not sure you will care for this level of suggestion, but:

I still believe you need to go back and revisit your database design, as I suggested in one of theprevious threads you posted about the scoring system. For instance, you have 10 Score tables right now If you had to add a new team it qould require you to add a new table to the database. However, you could easily have a single Team table with an additional field called "TeamNumber".
Then there is the Home table. Again, you would have to modify your database if you wanted to create a new Team. In one of the previous threads I outlined how you could modify the database so you wouldn't need a monthly job or any type of total fields, but if we were to modify just this current database, I would suggest changing your home table to something like:
Home
teamNumber
ID
etc...

Again, my first suggestion would be to go back and look atthe database structure I proposed in thread333-1259780. It would simplify the code you need a great deal, remove the need for a monthly job running on the server, and also give you the ability to have historical score tracking and be able to add more users without modifying the database. You hadn't mentioned teams before and this lookis slightly differantthan what you were working on in that thread, but the same logic could be used.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top