disable/able form buttons

Busy's picture

He has: 6,151 posts

Joined: May 2001

I've only seen this on programs so am not sure if it is possible with PHP

I have a form (well 4 html drop downs) , I want to disable the 'next' (submit) button until the drop downs are selected. I've got it set as an if statement as the moment (if all selected display button, else don't) but want the button link muted and unclickable until selected - like the agree button on install programs.

also the drop down options are selective, meaning some section only need 2 selected

can this be done with PHP?

Renegade's picture

He has: 3,022 posts

Joined: Oct 2002

I have never seen this done with PHP but I have seen it done with Javascript though. Don't know how to do it and can't find it anywhere either :S

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

<input type="submit" id="submitbutton" disabled="true" />'

And you can enable it using the DOM, something like:

document.getElementById("submitbutton").disabled=false;'

Add if/else statements around it to check if the dropdowns are all selected. Do you want help with that also? Smiling

Busy's picture

He has: 6,151 posts

Joined: May 2001

would rather not use javascript if can help it

I'm not sure you want to offer to do the if/else, it's over 1200 options in total from 35 main options. with PHP it's not so bad as the selected items can be checked against the database catagories and jumping from javascript to php and back would be massive amount of code to include a noscript option.

Abhishek Reddy's picture

He has: 3,348 posts

Joined: Jul 2001

Controlling form elements is only client-side, unfortunately. Flash/Java/etc can check with the server, but that's probably not a good option. Sad

Mark Hensler's picture

He has: 4,048 posts

Joined: Aug 2000

I had a project once where I had several drop downs who's values were dependant on previous drop downs. Nothing really special about this except the number of combinations that were possible. The solution we came up with was to use a database with a dependency table and php to print out a complex JavaScript to run the client-side form controls. The page was very heavy to load but performed as needed.

Mark Hensler
If there is no answer on Google, then there is no question.

Busy's picture

He has: 6,151 posts

Joined: May 2001

Oh well I guess I can scrap that idea, can use if/else on the next page, one more page wont hurt them Wink

thanks guys

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.