Thursday, September 19, 2024
Home » test7

test7

by Gods_Servant
<!DOCTYPE html>
<html>
    <head>
        <title>Radio button with Ajax and Parse</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    </head>
    <body>
        <form>
            <input type="radio" name="choice" value="1" id="choiceA"> Peace
            <input type="radio" name="choice" value="2" id="choiceB"> Joy
            <input type="radio" name="choice" value="3" id="choiceC"> Hope
        </form>
        <div id="result"></div>
        <script type="text/javascript">
            $(document).ready(function(){
                $('input[type=radio]').on('change', function(){
                    var choice = $(this).val();
                    // Sending value to Ajax
                    $.ajax({
                        type: "POST",
                        url: "ajax.php",
                        data: { choice: choice },
                        success: function(data) {
                            // Getting response from Parse Script
                            $('#result').html(data);
                        }
                    });
                });
            });
        </script>
    </body>
</html>

You may also like

Leave a Comment