This is my html code. It will print the book details along with checkbox option to select a particular book.
<div id="SearchBook" class="tabcontent">
<h3 align="center">Select the books</h3>
<center>
<form action= "searchbook" method="post" name="search" onsubmit="return searchForm()" >
<table cellpadding='10' cellspacing='5' border='2'>
<tr><td><b> Book ID </b></td><td><b> Book Name </b></td><td><b> Quantity </b></td><td><b> Select </b></td></tr>
<%
try{
Class.forName("org.postgresql.Driver");
Connection con=DriverManager.getConnection("jdbc:postgresql://localhost:5432/postgres","postgres","*");
Statement st= con.createStatement();
ResultSet resultSet = st.executeQuery("select * from librarydata1");
while(resultSet.next()){
%>
<tr><td><b><%= resultSet.getString(1) %></b></td><td><b><%= resultSet.getString(2) %></b></td><td><b><%= resultSet.getString(3) %></b></td><td><b> <input type="checkbox" name="checkselected" value="<%= resultSet.getString(1) %>" id = "checked" ></b></td></tr><br>
<%
}
%>
</table>
<br><input type="submit" name="select" value="Select" onclick ="bookselect()" ></form></center>
<%
}catch(Exception e){
out.println(e.getMessage());
}
%>
</div>
I tried this javascript code but it is not working
function searchForm() {
var x = document.forms["search"]["checkselected"].value;
if (x.checked==true ) {
alert("please select atleast one");
return false;
}
}
help me out.
Aucun commentaire:
Enregistrer un commentaire