moh.mehrabi moh.mehrabi - 1 year ago 65
Ajax Question

how add some textbox values in session in jsp page after click a button except form submit?

i have 5 textboxes and a buttom in my page.i want add these textboxes values in my session without form submitting.whats the problem in my code?

<meta charset="UTF-8">
<script src="js/jquery-1.10.2.js"></script>
$('#button').click(function() {
var val1 = $('#text1').val();
var val2 = $('#text2').val();
type: 'POST',
url: 'add.jsp',
data: { text1: val1, text2: val2 },
success: function(response) {
<form action="" method="post">
<input type="text" name="txt1" id="text1">
<input type="text" name="family" id="text2">
<label>article name</label>
<input type="text" name="uni">
<label>article place</label>
<input type="text" name="uniname">
<label>article grade</label>
<input type="text" name="unigrade">
<label>article date</label>
<input type="text" name="unitype">
<input type="button" name="button" id="button">
<input type="submit">

i dont recive any parameter in my add.jsp page to store in session.

Answer Source

$('#button').click is prematurely registered, not even the DOM elements are completely loaded, that's why it's not triggered. Move your code inside as follows:

$(function(){ //  hold till DOM becomes safe to manipulate.
    Put your code here.  
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download