I have multiple form input, I want to get all the value from the textfield.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<style type="text/css">
* {
.border-radius(0) !important;
}
#field {
margin-bottom:5px;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<input type="hidden" name="count" value="1" />
<div class="control-group" id="fields">
<label class="control-label" for="field1">Nice Multiple Form Fields</label>
<div class="controls" id="profs">
<form class="input-append" method='post' action='AddReqPo'>
<div id="field"><input autocomplete="off" class="input" id="field1" name="a" type="text" placeholder="Type something" data-items="8"/><button id="b1" class="add-more" type="button">+</button></div>
<input type='submit'>
</form>
<br>
<small>Press + to add another form field :)</small>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(){
var next = 1;
$(".add-more").click(function(e){
e.preventDefault();
var addto = "#field" + next;
var addRemove = "#field" + (next);
next = next + 1;
var newIn = '<input autocomplete="off" class="input" id="field' + next + '" name="a' + next + '" type="text">';
var newInput = $(newIn);
var removeBtn = '<button id="remove' + (next - 1) + '" class="btn-danger remove-me" >-</button></div><div id="field">';
var removeButton = $(removeBtn);
$(addto).after(newInput);
$(addRemove).after(removeButton);
$("#field" + next).attr('data-source',$(addto).attr('data-source'));
$("#count").val(next);
$('.remove-me').click(function(e){
e.preventDefault();
var fieldNum = this.id.charAt(this.id.length-1);
var fieldID = "#field" + fieldNum;
$(this).remove();
$(fieldID).remove();
});
});
});
</script>
</html>
this is the action (AddReqPo.java) for get the value from that form. The value assign into array. with the same name for the input.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Database db = (Database) getServletContext().getAttribute("db");
String[] a=request.getParameterValues("a");
System.out.println(a[0]);
System.out.println(a[1]);
System.out.println(a[2]);
response.sendRedirect("index.jsp");
}
but java.lang.NullPointerException
for System.out.println(a[0]);
how must I fix it?