I'm new to JavaScript. How can I print the values when an HTML form is submitted?
Asked
Active
Viewed 4,920 times
-1
-
what code have you got so far? have you asked my friend Google? – Joseph Mar 14 '12 at 07:05
-
Post your code, give more details, what value exactly? – slash197 Mar 14 '12 at 07:06
-
1Printing on the screen, or printing with a printer? – Dennis Mar 14 '12 at 07:07
-
printing on the screen itself. – sathish Mar 14 '12 at 12:49
2 Answers
0
Assuming your form looks like :
<form action="">
<input type="text" name="User" />
<input type="password" name="Password"/>
<span>Admin</span> <input type="checkbox" name="IsAdmin" />
<span>US</span> <input type="radio" name="Country" value="US" />
<span>UK</span> <input type="radio" name="Country" value="UK" />
<input type="submit" />
</form>
Jquery code should look like this as starting point :
<script type="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);
return false;
})
});
</script>

pokrate
- 3,954
- 7
- 30
- 36
0
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');
return false;
});

Tarun
- 1,888
- 3
- 18
- 30