Reputation: 3359
Simple jquery script:
$( "#action" ).submit(function( event )
{
if ($("#field_name").val() == 1 ){
alert('1');
return true;}
else {
alert('no');
return false;}
});
This script work with FF but nothing happens on IE. How to validate/check form on IE?
Upvotes: 0
Views: 68
Reputation: 93551
Your code works fine: http://jsfiddle.net/TrueBlueAussie/y4y83/1/
The most likely cause is not wrapping your jQuery in a DOM ready event.
$(function () {
$("#action").submit(function (event) {
if ($("#field_name").val() == 1) {
alert('1');
return true;
} else {
alert('no');
return false;
}
});
});
$(function () {
is just a shortcut for $(document).ready(function(){
Without that, the browser load time will have an impact, depending on the jQuery code placement (not at end of body etc)
The sample JSFiddles provided in comments had broken HTML. not also none of them included jQuery. please ensure you are including jQuery correctly.
Upvotes: 2
Reputation: 634
You can also use the onSubmit event in the HTML form code ; which is working better on IE.
<form ... onSubmit="return checkForm();">
// form
</form>
<script>
function checkForm(){
// your function that should return true or false
}
</script>
Upvotes: -1