|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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>
|
|
#2
|
||||
|
||||
|
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 |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
ive change the submits to buttons still the same result i think im doing something wrong with variables. :S global to local i dunno
|
|
#5
|
|||
|
|||
|
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>
|
|
#6
|
|||
|
|||
|
sigh . sorted. my buttons had the same id and name as the variable i was using
![]() |
|
#7
|
||||
|
||||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > En/disable multiple buttons onclick |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|