I am currently developing an e-commerce website and I want to offer users the option to select a different shipping address:
Shipping Details
<input type="button" value="Same as billing address" style="color: #FFFFFF;" class="link-style" onclick="test();" />
<table cellpadding="20">
<tr>
<td >Name : * </td>
<td><input type="text" id="name" name="name" /></td>
</tr>
<tr>
<td>Contact Number : </td>
<td><input type="text" name="cno" id="cno" /></td>
</tr>
<tr>
<td>Address : * </td>
<td><input type="text" name="address "id="address" /></td>
</tr>
<tr>
<td>City : *</td>
<td><input type="text" name="city" id="city" /></td>
</tr>
<tr>
<td>State : * </td>
<td><input type="text" name="state" id="state" /></td>
</tr>
<tr>
<td>Country : *</td>
<td><input type="text" name="country" id="country" /></td>
</tr>
</table>
If the user clicks on the button, all fields will be disabled. Otherwise, they can provide a different shipping address. I prefer not to use forms in this scenario. How can I pass these parameters to a JSP or servlet using session or post method? I have attempted AJAX but have encountered difficulties with implementation.
function setValue() {
alert("hi");
var name = document.getElementById("name").value;
var cno = document.getElementById("cno").value;
var address = document.getElementById("address").value;
var city = document.getElementById("city").value;
var state = document.getElementById("state").value;
var country = document.getElementById("country").value;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("post", "test.jsp", true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form- urlencoded");
xmlhttp.send("name=" + name);
xmlhttp.send("cno=" + cno);
xmlhttp.send("address=" + address);
xmlhttp.send("city=" + city);
xmlhttp.send("state=" + state);
xmlhttp.send("country=" + country);
}
The test.jsp page is not receiving the parameters.