在我的 jsp 页面中,我有一个 div,如下所示,我正在通过 javascript 事件设置它的值。
<div id="panel">Price
<div id="field_name" name="priceval"></div>
</div>
我在这里面临的问题是,我将 priceval 值设为 null
String price = request.getParameter("priceval");
int priceval = Integer.parseInt(price);
作为参考,这是我的整个 jsp 文件
<html>
<style media="screen" type="text/css">
#field_name { display:inline-block; }
</style>
<head>
<title>Online Book Store</title>
<script>
function myFunction() {
var quantityvalue=document.getElementById("quan").value;
var selObj = document.getElementById('selSeaShells');
var optionselectedvalue ;
// var optionselectedtext;
for (i=0; i<selObj.options.length; i++) {
if (selObj.options[i].selected) {
optionselectedvalue = selObj.options[i].value.split(':')[0];
}
}
var finalprice = quantityvalue*optionselectedvalue;
mydiv = document.getElementById("panel");
mydiv.style.display = "block"; //to show it
document.getElementById("field_name").innerHTML = finalprice;
}
function isNumberKey(evt){
var charCode = (evt.which) ? evt.which : event.keyCode
return !(charCode > 31 && (charCode < 48 || charCode > 57));
}
function hideDiv() {
mydiv = document.getElementById("panel");
mydiv.style.display = "none"; //to hide it
}
window.onload = function () {
hideDiv();
}
</script>
</head>
<Body Bgcolor = "wheat" onload="hideDiv()">
<center>
<h2> welcome to online shopping</h2>
<form Action = "./onlinebookstore">
select Book
<select name = "book" id="selSeaShells">
<option></option>
<option value= "100:C programming language">C programming language</option>
<option value = "200:Java programming language">Java programming language</option>
<option value = "300:Network analysis">Network analysis</option>
<option value = "400:Advaced computer Networks">Advaced computer Networks</option>
<option value ="500:Programming analysis">Programming analysis</option>
<option value = "600:Advanced data strctures">Advanced data strctures</option>
<option value = "700:Advanced java and web technologies">Advanced java and web technologies</option>
<option value = "800:Electronic devices">Electronic devices</option>
<option value = "900:Computer Graphics">Computer Graphics</option>
<option value = "1000:Microprocessors">Microprocessors</option>
<option value = "1100:Oracle">Oracle</option>
</select>
<br><br>
quantity <Input type = "text" name = "Quantity" id="quan" onkeypress="return isNumberKey(event);" onblur="myFunction()">
<br><br>
<div id="panel">Price
<div id="field_name" name="priceval"></div>
</div>
<input type = "submit" name = "s" value = "ADDItem">
<input type = "submit" name = "s" value = "Removeitem">
<input type = "submit" name = "s" value = "showitems">
<input type = "submit" value = "Logout" name = "s">
</form>
</center>
</Body>
</html>