How can I disable the submit button until all of the fields from the form are filled using javascript?
-
The form has a textbox and 3 dropdownlists. These are their id names: '#name (textbox), #country, #type, #adult'. I inserted in the select of the form.. I want them to be able to pick the options which has a value and after all dropdownlists and textbox has a value the submit button will enable. I can't figure it out.
-
Answer:
Use jQuery. The code is something like this: $('#submit').click(function(){ if ($('#name').val() == "") invalidForm() ; if ($('#country').val() == "") invalidForm() ; if ($('#type').val() == "") invalidForm() ; if ($('#adult').val() == "") invalidForm() ; return true; }); function invalidForm() { alert('please fill in the form'); return false; }
Ryuko at Answerbag.com Visit the source
Other answers
You attach a handler to the submit button. Your handler checks that everything is OK when submit gets clicked. Yes: return True and form submits. No: return False, and form does not submit (you can put up an error message too). There are other ways, but thats pretty easy.
Scumop
Related Q & A:
- How can I disable default blocks in Drupal 7 without touching the Blocks Config admin?Best solution by Drupal Answers
- How can I disable the new Yahoo popup?Best solution by malwaretips.com
- How can I disable caching and shadowing?
- How can I disable my pop-up button?Best solution by wikihow.com
- How can I disable this Auto-brightness feature?Best solution by Quora
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.