简体   繁体   中英

How to get values from a form and send it to Java class using javascript?

First i have declare that i am new to javascript. I have created a form that gets Id, Name, Age & Dept. I want it to send to java class and i have to show back the data along with the other data in the data Base using DWR.

For this i already done coding for showing the table, below that i have my form. After the form "Save" button calls the below function save(). Here, my form and function.

The Form:

Id:<input type="text" id="id"/><br>
Name:<input type="text" id="name"/><br>
Age:<input type="text" id="age"/><br>
Dept:<input type="text" id="dept"/><br>
<input id="Save" type="button" value="Save" onclick="save()"/>

The function:

function save(){
employee = new Object();
employee.id = dwr.util.getValue(iD);
employee.name = dwr.util.getValue(namE);
employee.age = dwr.util.getValue(agE);
employee.dept = dwr.util.getValue(depT);

dwr.engine.beginBatch();
Employee.aouEmployee(employee);  //   **Java method call to store data in DB**
fetch();//An another function which loads all the data in the table.
dwr.engine.endBatch();
}

But, i cant get proper output for the above function. I am also cant able to find the mistakes(due to no error msgs)

Any suggestions will be more appreciative

Thanks

UPDATES ARE HIGHLIGHTED BY BOLD

  1. Install Firefox, if you haven't already
  2. Install Firebug
  3. Use Firebug to debug JS, as well as its Net panel to debug AJAX calls; use console.log(string) to get feedback
  4. Profit.

By the way, for my curiosity: what's up with capitalising the last letter in a variable?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM