How can I check if form is not empty and if form is empty then set disabled=“disabled” into submit...
How can I check if form is not empty and if form is empty then set disabled="disabled"
into submit button?
<form action="/contact/" method="POST" id="form">
<input type="text" id="name" name="name" class="form-control" placeholder="Name">
<input type="email" id="email" name="email" class="form-control" placeholder="E-Mail">
<textarea name="msg" id="msg" class="form-control" rows="4" placeholder="Message"></textarea>
<input type="submit" value="Send" class="button-contac-send">
</form>
jquery html-form
add a comment |
How can I check if form is not empty and if form is empty then set disabled="disabled"
into submit button?
<form action="/contact/" method="POST" id="form">
<input type="text" id="name" name="name" class="form-control" placeholder="Name">
<input type="email" id="email" name="email" class="form-control" placeholder="E-Mail">
<textarea name="msg" id="msg" class="form-control" rows="4" placeholder="Message"></textarea>
<input type="submit" value="Send" class="button-contac-send">
</form>
jquery html-form
add a comment |
How can I check if form is not empty and if form is empty then set disabled="disabled"
into submit button?
<form action="/contact/" method="POST" id="form">
<input type="text" id="name" name="name" class="form-control" placeholder="Name">
<input type="email" id="email" name="email" class="form-control" placeholder="E-Mail">
<textarea name="msg" id="msg" class="form-control" rows="4" placeholder="Message"></textarea>
<input type="submit" value="Send" class="button-contac-send">
</form>
jquery html-form
How can I check if form is not empty and if form is empty then set disabled="disabled"
into submit button?
<form action="/contact/" method="POST" id="form">
<input type="text" id="name" name="name" class="form-control" placeholder="Name">
<input type="email" id="email" name="email" class="form-control" placeholder="E-Mail">
<textarea name="msg" id="msg" class="form-control" rows="4" placeholder="Message"></textarea>
<input type="submit" value="Send" class="button-contac-send">
</form>
jquery html-form
jquery html-form
edited Jan 27 '14 at 15:17


Abbas
11.9k63261
11.9k63261
asked Jan 27 '14 at 15:00
user3207076user3207076
5125
5125
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I'll tell you how you could do it, then try to get it to work. If your struggling post your code here and we'll help out. You can do this using Jquery or adding Required Field validators to your textbox.
If your going down the JQuery route, on click of your submit button(you will need to give it an ID attribute first) check if those fields are all empty. If they are then you can say return false. And that will cancel the submit event.
add a comment |
There are several libraries & native APIS to handle client side validation that are worth leveraging
HTML 5 Form Validation
You can use the required
attribute in any input and the browser will block client side submits:
<input id="name" name="name" required >
For more advanced handling, you can also wire up Javascript using the Constraint Validation API
jQuery Validate
Another popular client side validation framework is the jQuery Validation Plugin
Custom JavaScript
If you want to write yourself... assuming all fields are required, you'll need to capture change events to all inputs, verify that all inputs have a value, and then conditionally toggle the disabled attribute on the submit button. In jQuery, it would look something like this:
// get all input elements and attach listener
var $inputs = $("#myForm :input:not([type='submit'])")
$inputs.change(function() {
// check if all elements have value
var allInputsHaveValue = $inputs.toArray().every(function(el) {
return !!el.value
});
// toggle submit disabled
$("#submit").prop("disabled", !allInputsHaveValue);
}).change(); // run on init
Demo in jsFiddle
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21384098%2fhow-can-i-check-if-form-is-not-empty-and-if-form-is-empty-then-set-disabled-dis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'll tell you how you could do it, then try to get it to work. If your struggling post your code here and we'll help out. You can do this using Jquery or adding Required Field validators to your textbox.
If your going down the JQuery route, on click of your submit button(you will need to give it an ID attribute first) check if those fields are all empty. If they are then you can say return false. And that will cancel the submit event.
add a comment |
I'll tell you how you could do it, then try to get it to work. If your struggling post your code here and we'll help out. You can do this using Jquery or adding Required Field validators to your textbox.
If your going down the JQuery route, on click of your submit button(you will need to give it an ID attribute first) check if those fields are all empty. If they are then you can say return false. And that will cancel the submit event.
add a comment |
I'll tell you how you could do it, then try to get it to work. If your struggling post your code here and we'll help out. You can do this using Jquery or adding Required Field validators to your textbox.
If your going down the JQuery route, on click of your submit button(you will need to give it an ID attribute first) check if those fields are all empty. If they are then you can say return false. And that will cancel the submit event.
I'll tell you how you could do it, then try to get it to work. If your struggling post your code here and we'll help out. You can do this using Jquery or adding Required Field validators to your textbox.
If your going down the JQuery route, on click of your submit button(you will need to give it an ID attribute first) check if those fields are all empty. If they are then you can say return false. And that will cancel the submit event.
answered Jan 27 '14 at 15:11


CSharperCSharper
3,86542144
3,86542144
add a comment |
add a comment |
There are several libraries & native APIS to handle client side validation that are worth leveraging
HTML 5 Form Validation
You can use the required
attribute in any input and the browser will block client side submits:
<input id="name" name="name" required >
For more advanced handling, you can also wire up Javascript using the Constraint Validation API
jQuery Validate
Another popular client side validation framework is the jQuery Validation Plugin
Custom JavaScript
If you want to write yourself... assuming all fields are required, you'll need to capture change events to all inputs, verify that all inputs have a value, and then conditionally toggle the disabled attribute on the submit button. In jQuery, it would look something like this:
// get all input elements and attach listener
var $inputs = $("#myForm :input:not([type='submit'])")
$inputs.change(function() {
// check if all elements have value
var allInputsHaveValue = $inputs.toArray().every(function(el) {
return !!el.value
});
// toggle submit disabled
$("#submit").prop("disabled", !allInputsHaveValue);
}).change(); // run on init
Demo in jsFiddle
add a comment |
There are several libraries & native APIS to handle client side validation that are worth leveraging
HTML 5 Form Validation
You can use the required
attribute in any input and the browser will block client side submits:
<input id="name" name="name" required >
For more advanced handling, you can also wire up Javascript using the Constraint Validation API
jQuery Validate
Another popular client side validation framework is the jQuery Validation Plugin
Custom JavaScript
If you want to write yourself... assuming all fields are required, you'll need to capture change events to all inputs, verify that all inputs have a value, and then conditionally toggle the disabled attribute on the submit button. In jQuery, it would look something like this:
// get all input elements and attach listener
var $inputs = $("#myForm :input:not([type='submit'])")
$inputs.change(function() {
// check if all elements have value
var allInputsHaveValue = $inputs.toArray().every(function(el) {
return !!el.value
});
// toggle submit disabled
$("#submit").prop("disabled", !allInputsHaveValue);
}).change(); // run on init
Demo in jsFiddle
add a comment |
There are several libraries & native APIS to handle client side validation that are worth leveraging
HTML 5 Form Validation
You can use the required
attribute in any input and the browser will block client side submits:
<input id="name" name="name" required >
For more advanced handling, you can also wire up Javascript using the Constraint Validation API
jQuery Validate
Another popular client side validation framework is the jQuery Validation Plugin
Custom JavaScript
If you want to write yourself... assuming all fields are required, you'll need to capture change events to all inputs, verify that all inputs have a value, and then conditionally toggle the disabled attribute on the submit button. In jQuery, it would look something like this:
// get all input elements and attach listener
var $inputs = $("#myForm :input:not([type='submit'])")
$inputs.change(function() {
// check if all elements have value
var allInputsHaveValue = $inputs.toArray().every(function(el) {
return !!el.value
});
// toggle submit disabled
$("#submit").prop("disabled", !allInputsHaveValue);
}).change(); // run on init
Demo in jsFiddle
There are several libraries & native APIS to handle client side validation that are worth leveraging
HTML 5 Form Validation
You can use the required
attribute in any input and the browser will block client side submits:
<input id="name" name="name" required >
For more advanced handling, you can also wire up Javascript using the Constraint Validation API
jQuery Validate
Another popular client side validation framework is the jQuery Validation Plugin
Custom JavaScript
If you want to write yourself... assuming all fields are required, you'll need to capture change events to all inputs, verify that all inputs have a value, and then conditionally toggle the disabled attribute on the submit button. In jQuery, it would look something like this:
// get all input elements and attach listener
var $inputs = $("#myForm :input:not([type='submit'])")
$inputs.change(function() {
// check if all elements have value
var allInputsHaveValue = $inputs.toArray().every(function(el) {
return !!el.value
});
// toggle submit disabled
$("#submit").prop("disabled", !allInputsHaveValue);
}).change(); // run on init
Demo in jsFiddle
edited Nov 20 '18 at 18:42
answered Jan 27 '14 at 15:50


KyleMitKyleMit
58k34240397
58k34240397
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21384098%2fhow-can-i-check-if-form-is-not-empty-and-if-form-is-empty-then-set-disabled-dis%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown