Skip to content Skip to sidebar Skip to footer

Print Value On Form Submit

I'm new to JavaScript. How can I print the values when an HTML form is submitted?

Solution 1:

Assuming your form looks like :

<formaction=""><inputtype="text"name="User" /><inputtype="password"name="Password"/><span>Admin</span><inputtype="checkbox"name="IsAdmin" /><span>US</span><inputtype="radio"name="Country"value="US" /><span>UK</span><inputtype="radio"name="Country"value="UK" /><inputtype="submit" /></form>

Jquery code should look like this as starting point :

<scripttype="text/javascript">
        $(document).ready(function () {
            $("form").submit(function () {
                User = $("input[name='User']").val();
                Password = $("input[name='Password']").val();
                IsAdmin = $("input[name='IsAdmin']").attr("checked");
                Country = $("input:radio[name='Country']:checked").val(); /* Special case of radio buttons*/document.writeln(User);
                document.writeln(Password);
                document.writeln(IsAdmin);
                document.writeln(Country);

                returnfalse;
            })
        });
    </script>

Solution 2:

jQuery code is below:

$('#button_ID').submit(function() {
 alert('something');
});

button_ID is id of your submit button if you want to stop form to submit then add return false; at end

$('#button_ID').submit(function() {
 alert('something');
 returnfalse;
});

Post a Comment for "Print Value On Form Submit"