JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 7th, 2008, 09:19 PM
ninjured ninjured is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 136 ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 51 m 22 sec
Reputation Power: 7
En/disable multiple buttons onclick

hi guys so im having some drama with buttons and variables

bassicaly what im trying to do is when they click a button everything gets disabled then when they click the activate link all buttons get enabed again except the ones they clicked. all seemed pretty straight forward in my head however when reactivating the buttons only the one fist clicked doesnt get enabled instead of all buttons clicked.

so basically onclick of each button i just thought id set the variable to one so it knows its been clicked the just enable all the buttons where the variable is not equal to one. so the ones that havent been clicked. but no workys.

any help would be great. if that made any sense at all :S


Code:
<script type="text/javascript">
	var but_0 = 0;
	var but_1 = 0;
	var but_2 = 0;
	var but_3 = 0;
	var but_4 = 0;
	var but_5 = 0;
	var but_6 = 0;
	var but_7 = 0;
	var but_8 = 0;

function disableAll(){
	document.myform0.but_0.disabled=true;
	document.myform1.but_1.disabled=true;
	document.myform2.but_2.disabled=true;
	document.myform3.but_3.disabled=true;
	document.myform4.but_4.disabled=true;
	document.myform5.but_5.disabled=true;
	document.myform6.but_6.disabled=true;
	document.myform7.but_7.disabled=true;
	document.myform8.but_8.disabled=true;
	return true;
	}		
function enableAll(){
	if(but_0!=1){document.myform0.but_0.disabled=false;}
	if(but_1!=1){document.myform1.but_1.disabled=false;}
	if(but_2!=1){document.myform2.but_2.disabled=false;}
	if(but_3!=1){document.myform3.but_3.disabled=false;}
	if(but_4!=1){document.myform4.but_4.disabled=false;}
	if(but_5!=1){document.myform5.but_5.disabled=false;}
	if(but_6!=1){document.myform6.but_6.disabled=false;}
	if(but_7!=1){document.myform7.but_7.disabled=false;}
	if(but_8!=1){document.myform8.but_8.disabled=false;}
	return true;
	}		
</script>


<form   action="" name="myform0" id="myform0">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="0" />
<input onclick="but_0=1;disableAll();" type="submit" id="but_0" name="but_0" value="Run Batch 0 - 1000" /></form>

<form   action="" name="myform1" id="myform1">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="1" />
<input onclick="but_1=1;disableAll();" type="submit" id="but_1" name="but_1" value="Run Batch 1000 - 2000" /></form>

<form   action="" name="myform2" id="myform2">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="2" />
<input onclick="but_2=1;disableAll();" type="submit" id="but_2" name="but_2" value="Run Batch 2000 - 3000" /></form>

<form   action="" name="myform3" id="myform3">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="3" />
<input onclick="but_3=1;disableAll();" type="submit" id="but_3" name="but_3" value="Run Batch 3000 - 4000" /></form>

<form   action="" name="myform4" id="myform4">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="4" />
<input onclick="but_4=1;disableAll();" type="submit" id="but_4" name="but_4" value="Run Batch 4000 - 5000" /></form>

<form   action="" name="myform5" id="myform5">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="5" />
<input onclick="but_5=1;disableAll();" type="submit" id="but_5" name="but_5" value="Run Batch 5000 - 6000" /></form>

<form   action="" name="myform6" id="myform6">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="6" />
<input onclick="but_6=1;disableAll();" type="submit" id="but_6" name="but_6" value="Run Batch 6000 - 7000" /></form>

<form   action="" name="myform7" id="myform7">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="7" />
<input onclick="but_7=1;disableAll();" type="submit" id="but_7" name="but_7" value="Run Batch 7000 - 8000" /></form>

<form   action="" name="myform8" id="myform8">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="8" />
<input onclick="but_8=1;disableAll();" type="submit" id="but_8" name="but_8" value="Run Batch 8000 - 9000" /></form>			

<a href="#" onclick="javascript:enableAll();">Please Click Here to activate the rest of the batch jobs</a>

Reply With Quote
  #2  
Old May 8th, 2008, 03:32 AM
KorRedDevil's Avatar
KorRedDevil KorRedDevil is online now
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Aug 2005
Location: Bucharest ROMANIA
Posts: 1,506 KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 14 h 40 sec
Reputation Power: 55
Send a message via Yahoo to KorRedDevil
My dilemma is that you use submit buttons. When you press a submit button, that starts a submit action, which will change the session, thus all the javascript changes are lost... So I see no point in your codes...

What is your final aim, after all? Why do you need to disable the buttons and when?
__________________
HELP SAVE ANA

Reply With Quote
  #3  
Old May 8th, 2008, 03:58 AM
ninjured ninjured is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 136 ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 51 m 22 sec
Reputation Power: 7
ok submit buttons are used because each form is actually submitted when the button is clicked. via ajax into a div <form action=""> hence why its ommitted

the page doesnt actually go anywhere when the submit buttons are pressed so i assumed it wouldnt renew the variables. but maybe this is what its doing ? i figured it wouldnt as the page isnt being refreshed.

bassically when a button is pressed it is disabled forever (while they are on the page) but by pressing a button all buttons are temporary disabled while the ajax div area executes so the user cant press another button. when this has finshed a link comes up which i have at the bottom to reactivate the buttons that have not been clicked yet ? essentially its batch processing alot of records which takes a while in lots of 1000. but you cant click a button twice or click anotherone while processing is occuring.

Reply With Quote
  #4  
Old May 8th, 2008, 04:06 AM
ninjured ninjured is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 136 ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 51 m 22 sec
Reputation Power: 7
ive change the submits to buttons still the same result i think im doing something wrong with variables. :S global to local i dunno

Reply With Quote
  #5  
Old May 8th, 2008, 04:58 AM
ninjured ninjured is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 136 ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 51 m 22 sec
Reputation Power: 7
here is a kind of cleaned up version with buttons still presenting the same problem ?

Code:
<script type="text/javascript">
	var but_0 = 0;
	var but_1 = 0;
	var but_2 = 0;
	var but_3 = 0;

function disableAll(){
	document.myform0.but_0.disabled=true;
	document.myform1.but_1.disabled=true;
	document.myform2.but_2.disabled=true;
	document.myform3.but_3.disabled=true;
	return true;
	}		
function enableAll(){
	if(but_0!=1){document.myform0.but_0.disabled=false;}
	if(but_1!=1){document.myform1.but_1.disabled=false;}
	if(but_2!=1){document.myform2.but_2.disabled=false;}
	if(but_3!=1){document.myform3.but_3.disabled=false;}
	return true;
	}		
</script>


<form name="myform0" id="myform0">
<input onclick="but_0=1;disableAll();" type="button" id="but_0" name="but_0" value="Run Batch 0 - 1000" /></form>

<form name="myform1" id="myform1">
<input onclick="but_1=1;disableAll();" type="button" id="but_1" name="but_1" value="Run Batch 1000 - 2000" /></form>

<form name="myform2" id="myform2">
<input onclick="but_2=1;disableAll();" type="button" id="but_2" name="but_2" value="Run Batch 2000 - 3000" /></form>

<form name="myform3" id="myform3">
<input onclick="but_3=1;disableAll();" type="button" id="but_3" name="but_3" value="Run Batch 3000 - 4000" /></form>


<a href="#" onclick="javascript:enableAll();">Please Click Here to activate the rest of the batch jobs</a>

Reply With Quote
  #6  
Old May 8th, 2008, 05:01 AM
ninjured ninjured is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 136 ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level)ninjured User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 51 m 22 sec
Reputation Power: 7
sigh . sorted. my buttons had the same id and name as the variable i was using

Reply With Quote
  #7  
Old May 8th, 2008, 08:05 AM
KorRedDevil's Avatar
KorRedDevil KorRedDevil is online now
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Aug 2005
Location: Bucharest ROMANIA
Posts: 1,506 KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level)KorRedDevil User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 2 Weeks 2 Days 14 h 40 sec
Reputation Power: 55
Send a message via Yahoo to KorRedDevil
Ok, I guess you need something like this:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function enableAll(){
var i=0,b;
while(b=document.getElementById('but_'+(i++))){
b.disabled=b.dis?b.dis:false;
}
}
function disableAll(obj){
var i=0,b;
while(b=document.getElementById('but_'+(i++))){
!b.dis?b.dis=b==obj?true:false:null;
b.disabled=true;
}
}
</script>
</head>
<body>
<form   action="" name="myform0" id="myform0">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="0" />
<input onclick="disableAll(this)" type="button" id="but_0" name="but_0" value="Run Batch 0 - 1000" /></form>

<form   action="" name="myform1" id="myform1">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="1" />
<input onclick="disableAll(this)" type="button" id="but_1" name="but_1" value="Run Batch 1000 - 2000" /></form>

<form   action="" name="myform2" id="myform2">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="2" />
<input onclick="disableAll(this)" type="button" id="but_2" name="but_2" value="Run Batch 2000 - 3000" /></form>

<form   action="" name="myform3" id="myform3">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="3" />
<input onclick="disableAll(this)" type="button" id="but_3" name="but_3" value="Run Batch 3000 - 4000" /></form>

<form   action="" name="myform4" id="myform4">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="4" />
<input onclick="disableAll(this)" type="button" id="but_4" name="but_4" value="Run Batch 4000 - 5000" /></form>

<form   action="" name="myform5" id="myform5">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="5" />
<input onclick="disableAll(this)" type="button" id="but_5" name="but_5" value="Run Batch 5000 - 6000" /></form>

<form   action="" name="myform6" id="myform6">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="6" />
<input onclick="disableAll(this)" type="button" id="but_6" name="but_6" value="Run Batch 6000 - 7000" /></form>

<form   action="" name="myform7" id="myform7">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="7" />
<input onclick="disableAll(this)" type="button" id="but_7" name="but_7" value="Run Batch 7000 - 8000" /></form>

<form   action="" name="myform8" id="myform8">
<input type="hidden" name="mailid" value="53" />
<input type="hidden" name="nume" value="8" />
<input onclick="disableAll(this)" type="button" id="but_8" name="but_8" value="Run Batch 8000 - 9000" /></form>			

<a href="#" onclick="enableAll();">Please Click Here to activate the rest of the batch jobs</a>
</body>
</html>

Feel free to ask whichever you don't understand in my code
Comments on this post
ninjured agrees: ah yes that is a much cleaner solution. many thanks. much appreciated.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > En/disable multiple buttons onclick


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway