Actually, when my form is submitted with the submit button, I would want that the javascript code is executed for checking datas and if datas are not filled, to open a popup dialog and so, don't execute the action bounded to the form.
Unfortunately, the javascript code is never executed even if the javascript is on the top of the page.
Do you have a solution ?
Thank you
My form :
@using (Html.BeginForm("AddRecipe", "AddRecipe", FormMethod.Post, new { data_ajax = "false"}))
{
//Set of components to submit
//etc
<input type="submit" data-theme="b" id="addRecipeBtn" onclick="checkDatas();" value="Ajouter ma recette" />
}
My javascript code to execute :
<script>
function checkDatas() {
alert("ici");
var ok = $("#fakeInput").val().length != 0 &&
$("#title").val().length != 0 &&
$("#cookingTime").val().length != 0 &&
$("#preparationTime").val().length != 0 &&
$("#ingredientListArea").val().length != 0 &&
$("#preparationArea").val().length != 0;
if (!ok) {
$("#popupDialog").popup("open");
}
}
</script>