Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
98
rated 0 times [  104] [ 6]  / answers: 1 / hits: 27061  / 11 Years ago, tue, october 1, 2013, 12:00:00

I searched a lot but couldn't find an answer for my question.
Firstly, i would like to have a submit button which will be disable if all the required fields are not filled.
I found some example if all the fields are filled but i have required and not required ones So,
I need to find if the required ones are filled or not.
I am currently out of ideas of how to make it happen.
Just in case , i am using play framework 2.1.x with Scala.



Cheers,
Ilgün


More From » jquery

 Answers
10

This should work:


<script>
$(function () {
var submitButton = $("#myForm input[type='submit']");
$("#myForm input.required").change(function () {
var valid = true;
$.each($("#myForm input.required"), function (index, value) {
alert("comes here");
if(!$(value).val()){
valid = false;
}
});
if(valid){
$(submitButton).attr("disabled", false);
console.log("valid");
alert("valid");
}
else{
$(submitButton).attr("disabled", true);
}
});
});

</script>

My submit Button:


<input type="submit" class="btn btn-primary" value="Submit" id="form-submit" onclick="return myConfirm();" />

[#75304] Monday, September 30, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
joep

Total Points: 32
Total Questions: 97
Total Answers: 104

Location: Wales
Member since Thu, Jul 1, 2021
3 Years ago
;