How would I disable a button?

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

How would I disable a button?

Post by legend986 »

I have a series of radio boxes on a php page. Depending on some conditions, I'm disabling them or enabling. With this, a situation may arise where all the radio boxes are disabled. How would I disable the submit button when all the radio buttons are disabled?
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Set the disabled attribute on the submit button.
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Post by legend986 »

No, i mean how would i check if all the radio boxes are disabled? If one or two are disabled, I don't want to disable the submit button...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

PHP has no control over this stuff. Moved to Client Side.
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Post by legend986 »

My bad logic.. Sorry again :(
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Post by legend986 »

Got it!

Code: Select all

<script language="javascript">
window.onload = function(){
	var count1;
	count1 = 0;
	for(i=0;i<document.course.course_id.length;i++) {
		if(document.course.course_id[i].disabled == true)
			count1++;
	}
	if(count1 == document.course.course_id.length)
		document.course.course.disabled=true;

}
</script>
Thank You :)
Post Reply