javascript - How to submit form using radio option -
i'm doing website in safari. works in safari, firefox , chrome. in explorer it's not working properly. here want submit form , direct page when radio option clicked. have used onchange="this.form.submit();
in input. not work in explorer. please suggest me solution. have tried query too. that's not working. have attached code below.
<script src="https://code.jquery.com/jquery-1.9.1.js"></script> <script type="text/javascript" language="javascript"> (function(document, window, $, undefined) { var form = $('#form-id'); $('.radio-class').each(function(i, element) { var radio = $(element); radio.on('change', function() { // selected value var radiovalue = $(this).val(); form.submit(); }); }); }(document, window, jquery, undefined)); </script> <body> <form action="go.php" method="post" id="form-id"> <label for="radio-select"><input type="radio" name="radio-select" value="mango" class="radio-class">mango</label> <label for="radio-select"><input type="radio" name="radio-select" value="apple" class="radio-class">apple</label> <label for="radio-select"><input type="radio" name="radio-select" value="pinaple" class="radio-class">pinaple</label> </form> </body>
try way:
<script> $(document).ready(function(){ var form = $('#form-id'); $('.radio-class').each(function(i, element){ var radio = $(element); radio.on('change', function(){ // selected value var radiovalue = $(this).val(); form.submit(); }); }); }); </script>
the code inside $(document).ready() executed after dom loaded. way, .radio-class
elements exist when listener change
event added.
it's explained better here.
this example simplified loop:
$(document).ready(function(){ var form = $('#form-id'); $('.radio-class').on('change', function(){ form.submit(); }); });
and shorthand $(document).ready()
$(function(){ var form = $('#form-id'); $('.radio-class').on('change', function(){ form.submit(); }); });
Comments
Post a Comment