Say I've a simple form
and I want to check whether form
has changed or not. If its changed submit
it else prevent form submission, so I used return and instead of using if-else
statement I tried to use ternary operation
but unfortunately I was hit with error Uncaught SyntaxError: Unexpected token return
but I did not understand why this error? Is ternary operation only used to assign? Not sure on this part. Below is just a sample of what I was trying to do.
var form_original_data = $(#frmProfile).serialize();
$(#frmProfile).on('submit', function(e) {
e.preventDefault();
$(#frmProfile).serialize() != form_original_data ? $(body).append('changed') : return;
})
<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<form id=frmProfile>
<input type=text value=name />
<input type=submit value=Go />
</form>