HTML - DIV not hiding - javascript

I have a project based in Spring Web model-view-controller (MVC) framework. The version of the Spring Web model-view-controller (MVC) framework is 3.2.8
I have this piece of code in my JSP
<div class="col-md-12" id="secondSignatoryDivId" >
<table width="100%">
<thead>
<tr>
<th><b>First name</b></th>
<th><b>Last name</b></th>
<th><b>Position</b></th>
<th><b>Title</b></th>
<th><b>Actions</b></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="text" value="${deviceForm.device.secondSignatory.firstname}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td><input type="text" value="${deviceForm.device.secondSignatory.lastname}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td><input type="text" value="${deviceForm.device.secondSignatory.position}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td><input type="text" value="${deviceForm.device.secondSignatory.title}" <c:if test="${readonly}">disabled="disabled"</c:if> class="form-control"/></td>
<td>Delete</td>
</tr>
</tbody>
</table>
</div>
<c:if test="${empty applicationForm.application.secondSignatory}">
<script>
alert ('lalalal');
$('#secondSignatoryDivId').hide();
</script>
</c:if>
I see the alert but the div does not hide !

You are using jQuery, you should include jQuery on your html file:
alert('lalalal');
$('#secondSignatoryDivId').hide();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-12" id="secondSignatoryDivId">
<table width="100%">
<thead>
<tr>
<th><b>First name</b>
</th>
<th><b>Last name</b>
</th>
<th><b>Position</b>
</th>
<th><b>Title</b>
</th>
<th><b>Actions</b>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.firstname}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.lastname}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.position}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>
<input type="text" value="${deviceForm.device.secondSignatory.title}" <c:if test="${readonly}">disabled="disabled"</c:if>class="form-control"/></td>
<td>Delete</td>
</tr>
</tbody>
</table>
</div>

If it is just for hiding the element then better to do it with css:
<c:if test="${empty applicationForm.application.secondSignatory}">
<style>
#secondSignatoryDivId.col-md-12 { display:none; }
</style>
</c:if>

Related

html form to PDF issue

Issue: Word is wrapping when I am typing in the html page. But, after downloading the form as PDF, it is not showing the word as wrapped. Please see the screenshot below:
Before downloading
After downloading
// download contents of the page
document.getElementById("download").addEventListener("click", () => {
const formBox = document.getElementById("formBox");
var opt = {
margin: 0,
filename: "caseFile" + request + ".pdf",
html2canvas: {
scale: 2
},
jsPDF: {
unit: 'in',
format: 'letter',
orientation: 'portrait'
}
};
html2pdf().from(formBox).set(opt).save();
})
<form id="formBox">
<table id="caseInfo">
<tr>
<th colspan="2">Case Info</th>
</tr>
<tr>
<td>Date of Offense</td>
<td>
<input type="date" id="dateOffense">
</td>
</tr>
<tr>
<td>Time of Offense</td>
<td><input type="time" id="timeOffense"></td>
</tr>
<tr>
<td>Location of Offense</td>
<td><input type="text" id="locationOffense"></td>
</tr>
<tr>
<td>City</td>
<td><input type="text" id="caseCity"></td>
</tr>
<tr>
<td>Zip</td>
<td><input type="text" id="caseZip"></td>
</tr>
<tr>
<td>Type of Offense</td>
<td><input type="text" id="typeOffense"></td>
</tr>
</table>
<br>
<div class="row">
<table class="column" id="caseAuthorizedBy">
<tr>
<th colspan="2">Case Authorized By</th>
</tr>
<tr>
<td>Consent</td>
<td>
<input type="radio" name="search" id="consent">
</td>
</tr>
<tr>
<td>Search Warrant</td>
<td><input type="radio" name="search" id="searchWarrant"></td>
</tr>
<tr>
<td>Deceased</td>
<td><input type="radio" name="search" id="Deceased"></td>
</tr>
<tr>
<td>Other(Specify)</td>
<td><input type="radio" name="search" id="otherSearch"></td>
</tr>
</table>
<br>
<table class="column" id="custodyInformation">
<tr>
<th colspan="2">Custody Info</th>
</tr>
<tr>
<td>In-Custody</td>
<td> <input type="radio" name="custody" id="inCustody"></td>
</tr>
<tr>
<td>Not In-Custody</td>
<td><input type="radio" name="custody" id="notInCustody"></td>
</tr>
</table>
</div>
<br><br>
<div id="root0"></div>
<!-- <hr> -->
<br><br>
<div id="analysisDiv">
<table id="analysisTable">
<tr>
<th colspan="1">Analysis</th>
</tr>
<tr>
<td><textarea id="analysis" rows="15" cols="20" wrap="hard" name="text" /></textarea>
</td>
</tr>
</table>
</div>
<br>
</form>
<!--PDF download button-->
<div class="downloadButton">
<button class="button-15" id="download">Download PDF</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
I need help with this. I have tried many examples I found online. But couldn't find anything helpful. I am new to JavaScript, so I don't know any effective way of doing this. If my javascript is incorrect or not an effective way of doing it feel free to provide new code or way of doing this. I am totally lost. Help would be appreciated. Thanks!

Insert more fields onclick using jquery

I'm working on a web application that gives user the chance to input more names as user wishes. the form has a link that has to perform an addition of textboxes on click of that link.
i know there is a way to use jquery to do that but currently don't know why cos i just moved to jquery from angularjs
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="form1" method="post" action="">
<table width="50%" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><div align="right"><strong>Add More Fields</strong></div></td>
</tr>
<tr>
<td>Name</td>
<td>Address</td>
<td>Age</td>
<td>Phone Number</td>
</tr>
<tr>
<td><input type="text" name="name" id="name"></td>
<td><input type="text" name="address" id="address"></td>
<td><input type="text" name="age" id="age"></td>
<td><input type="text" name="phone_number" id="phone_number"></td>
</tr>
</table>
</form>
$(document).ready(function()
{
$('a').click(function(){
var id=$(':text').length;
$('#field').append('<td>Textbox'+id+'</td>');
$('#more').append('<td><input type="text" id='+id+' name="text'+id+'"></td>');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="form1" method="post" action="">
<table width="50%" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><div align="right"><strong>Add More Fields</strong></div></td>
</tr>
<tr id="field">
<td>Name</td>
<td>Address</td>
<td>Age</td>
<td>Phone Number</td>
</tr>
<tr id="more">
<td><input type="text" name="name" id="name"></td>
<td><input type="text" name="address" id="address"></td>
<td><input type="text" name="age" id="age"></td>
<td><input type="text" name="phone_number" id="phone_number"></td>
</tr>
</table>
</form>
or try this one
$(document).ready(function()
{
$('a').click(function(){
var id=$(':text').length;
$('#more td').append('<input type="text" id='+id+' name="text'+id+'">');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style type="text/css">
input{
margin-bottom: 10px;
}
</style>
<form name="form1" method="post" action="">
<table width="50%" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><div align="right"><strong>Add More Fields</strong></div></td>
</tr>
<tr id="field">
<td>Name</td>
<td>Address</td>
<td>Age</td>
<td>Phone Number</td>
</tr>
<tr id="more">
<td><input type="text" name="name" id="name"></td>
<td><input type="text" name="address" id="address"></td>
<td><input type="text" name="age" id="age"></td>
<td><input type="text" name="phone_number" id="phone_number"></td>
</tr>
</table>
</form>
First you have to identify better your elements. Let's put an id for table, an id for add more fields link and a class for tr model.
Then we have to copy all html you want to duplicate.
Then append it to table.
Remember that doing this, when you submit, all those duplicate parameters will become an array of values.
Let's refactor some bad code here too.
Since we are duplicating fields we need to remove Id attribute of them all.
I'm moving add link outside the table and removing those blank tds. Also write a good table with thead and tbody.
When we want to add field, we want to remove too. So let's create a link to remove.
function cloneTrModel() {
return $('.model').first().clone();
}
var trModel = cloneTrModel();
function setRemove() {
$(".remove" ).click(function() {
$(this).closest('tr').remove();
});
}
setRemove();
$( "#add" ).click(function() {
$("#contactTable tbody").append(trModel);
trModel = cloneTrModel();
setRemove();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="form1" method="post" action="">
<strong style="float: right;">Add More Fields</strong>
<table id="contactTable" width="50%" border="0" align="center" cellpadding="5" cellspacing="5">
<thead>
<tr>
<th>Name</th>
<th>Address</th>
<th>Age</th>
<th>Phone Number</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class="model">
<td class="inner"><input type="text" name="name[]"></td>
<td><input type="text" name="address[]"></td>
<td><input type="text" name="age[]"></td>
<td><input type="text" name="phone_number[]"></td>
<td>Remove</td>
</tr>
</tbody>
</table>
</form>
Something like that
$( "#add" ).click(function() {
$( ".inner" ).append( "<input type='text' name='name' id='name'>" );
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form name="form1" method="post" action="">
<table width="50%" border="0" align="center" cellpadding="5" cellspacing="5">
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><div align="right"><strong>Add More Fields</strong></div></td>
</tr>
<tr>
<td>Name</td>
<td>Address</td>
<td>Age</td>
<td>Phone Number</td>
</tr>
<tr>
<td class="inner"><input type="text" name="name" id="name"></td>
<td><input type="text" name="address" id="address"></td>
<td><input type="text" name="age" id="age"></td>
<td><input type="text" name="phone_number" id="phone_number"></td>
</tr>
</table>
</form>

Convert existing input and table to Kendo Textbox and Kendo Grid

I have a login form and I would like to kendofy it i.e. basically convert it into a responsive form like this: http://demos.telerik.com/kendo-ui/validator/index
Is there a quick way that would allow me to convert my existing username and password fields to kendo textbox fields such that I am able to achieve the responsive design without actually creating the fields again myself? Looking forward to your suggestions.
My Form:
<form action="https://../Portal" method="post" name="loginForm">
<input name="act" value="portalLogin" type="hidden">
<input name="c" value="12912" type="hidden">
<input name="p" value="101074" type="hidden">
<input name="d" value="101076" type="hidden">
<input name="g" value="101097" type="hidden">
<input name="objDefId" value="13439" type="hidden">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td>
<div id="rbi_S_101098" name="Notification Message">
<table class="wide rbwhite" cellpadding="0" cellspacing="0">
<tbody>
<tr>
</tr>
</tbody>
</table>
</div>
<table class="wide" height="10px">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<div class="k-content" id="rbi_S_101100" name="User Login">
<table class="wide rbwhite" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td colspan="2">
<table>
<tbody>
<tr>
<td nowrap="" align="right"><strong>Login Name </strong>
</td>
<td nowrap="">
<input class="k-textbox" name="loginName" maxlength="50" size="40" type="text">
</td>
</tr>
<tr height="5">
<td></td>
</tr>
<tr>
<td nowrap="" align="right"><strong>Password </strong>
</td>
<td nowrap="">
<input class="k-textbox" name="password" maxlength="50" size="40" type="password">
</td>
</tr>
<tr height="5">
<td></td>
</tr>
<tr>
<td></td>
<td alignmant="right" nowrap="">
<strong><input class="btn btn-small" value=" Login " type="submit"></strong> </td>
</tr>
<tr height="5">
<td></td>
</tr>
<tr>
<td></td>
<td alignment="right" nowrap="">
Forgot your password? </td>
</tr>
</tbody>
</table>
</td>
<script>
document.loginForm.loginName.focus();
</script>
</tr>
<tr>
</tr>
</tbody>
</table>
</div>
<table class="wide" height="10px">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<div id="rbi_S_114558" name="Scripts Section">
<table class="wide rbwhite" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td class="detailHTMLCol" colspan="2">
</td>
</tr>
</tbody>
</table>
</div>
<table class="wide" height="10px">
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</form>
Cheers.

how to display edit input fields in lightbox using css3 in html5

I am new to html5 , on my layout I placed an "edit" button in a table row. When we click on edit button it displays particular row fields on light box with same layout. My problem is that when I click on edit button it should display particular row details in another window.
This is my table and edit button code in jsp:
<body onload="altRows();">
<%#include file="dbheader.jsp" %>
<table class="altrowstable" id="alternatecolor">
<tr>
<th>code</th>
<th>Name</th>
<th>Phone</th>
<th>Address1</th>
<th>Address2</th>
<th>Postal Code</th>
<th>E-mail</th>
<th>Website</th>
<th>Blog</th>
<th>Fax</th>
<th>City</th>
<th>State</th>
<th>Longitude</th>
<th>Latitude</th>
<th>Date</th>
</tr>
<c:forEach items="${businesslist}" var="business">
<tr>
<td>${business.busent_code}</td>
<td>${business.busent_name}</td>
<td>${business.busent_phone}</td>
<td>${business.busent_address1}</td>
<td>${business.busent_address2}</td>
<td>${business.busent_postal_code}</td>
<td>${business.busent_email}</td>
<td>${business.busent_website}</td>
<td>${business.busent_blog}</td>
<td>${business.busent_fax}</td>
<td>${business.busent_city}</td>
<td>${business.busent_state}</td>
<td>${business. busent_longitude}</td>
<td>${business.busent_latitude}</td>
<td>${business.busent_date}</td>
<form:form commandName="business" action="updatebusinessess" method="post" >
<td> <form:input id="busent_name" path="busent_name" type="hidden" value="${business.busent_name}"/>
<input id="submit" type="button" onclick="javascript:return lightbox();" tabindex="5"value="Edit">
</form:form>
<td>Show Map</td>
<td><input type="checkbox"></td>
</tr>
</c:forEach>
</table>
<table border="0" cellpadding="5" cellspacing="5" align="center">
<tr>
<%--For displaying Previous link except for the 1st page --%>
<c:if test="${currentPage != 1}">
<td>Previous</td>
</c:if>
<%--For displaying Page numbers.The when condition does not display a link for the current page-- %>
<c:forEach begin="1" end="${noOfPages}" var="i">
<c:choose>
<c:when test="${currentPage eq i}">
<td>${i}</td>
</c:when>
<c:otherwise>
<td>${i}</td>
</c:otherwise>
</c:choose>
</c:forEach>
<%--For displaying Next link --%>
<c:if test="${currentPage lt noOfPages}">
<td>Next</td>
</c:if>
</tr>
</table> <br><br>
<%# include file="dbfooter.jsp" %>
this my lightbox and row fields code in jsp.
<div id="light1" class="content2">
<form:form commandName="business" action="savebusinessess" method="post" runat="server">
<table border="0">
<c:forEach items="${businesslist}" var="business" >
<tr>
<th>Name</th>
<td><form:input path="busent_name" value="${business.busent_name}" size="30"/></td>
</tr>
<tr>
<th>Address1</th>
<td><form:input path="busent_address1" value="${business.busent_address1}" size="30"/></td>
</tr>
<tr>
<th>Address2</th>
<td><form:input path="busent_address2" value="${business.busent_address2}" size="30"/></td>
</tr>
<tr>
<th>City</th>
<td><form:input path="busent_city" value="${business.busent_city}" size="30"/></td>
</tr>
<tr>
<th>State</th>
<td><form:input path="busent_state" value="${business.busent_state}" size="30"/></td>
</tr>
<tr>
<th>Phone</th>
<td><form:input path="busent_phone" value="${business.busent_phone}" size="30"/></td>
</tr>
<tr>
<th>Website</th>
<td><form:input path="busent_website" value="${business.busent_website}" size="30"/></td>
</tr>
<tr>
<th>Zip code</th>
<td><form:input path="busent_postal_code" value="${business.busent_postal_code}" size="30"/> </td>
</tr>
<tr>
<th>Longitude</th>
<td><form:input path="busent_longitude" value="${business.busent_longitude}" size="30"/></td>
</tr>
<tr>
<th>Latitude</th>
<td><form:input path="busent_latitude" value="${business.busent_latitude}" size="30"/></td>
</tr>
<tr>
<th>Date:</th>
<td><form:input path="busent_date" value="${business.busent_date}" size="30"/></td>
</tr>
</c:forEach>
</table>
<input id="submit" type="submit" align="left" value="update Details" onclick="myFunction();"/>
</form:form>
Close
</div>
i am getting lightbox but i get all table rows display on lightbox.
controller:
#Controller
public class UpdateController {
#Autowired
private UpdateService updateService;
private static final Log logger = LogFactory.getLog(UpdateController.class);
#RequestMapping(value = "/updatebusinessess")
public String updateBusinessess(Business business,Model model) {
logger.info("updatebusinessess");
List<Business> bus=updateService.updateBusinessdetails(business);
model.addAttribute("businesslist",bus);
model.addAttribute("business",new Business());
return "updatingdetails";
}
#RequestMapping(value = "/savebusinessess")
public String addBusinessess(Business business, BindingResult result) {
logger.info("addbusinessess");
updateService.saveBusinessdetails(business);
return "success";
}
#RequestMapping(value = "/update")
public String updateBusiness( Model model) {
logger.info("updatebusiness");
model.addAttribute("business",new Business());
return "updatebusinessdetails";
}
}
The idea here is that you should create a lightbox itself first to be in DOM. For example:
<div id="lightbox1">
<input type="text" id="name1"/>
<input type="text" id="address1"/>
...
</div>
Your button should fill its input with specific value. You can use also jQuery:
$("#name1").val("John");
$("#address1").val("My street 1");
...
I think the idea is clear now. If so, you need just take values from the row instead of "John" and "My street 1". The simplest way will be to name every component in rows for using in jQuery or you can find parent element for the every button on the row and relatively to that find particular inputs (this will be little challenging if you're new to HTML and JS).
For lightbox you can use any lightbox solution written in jQuery and attach the "div" element to that lightbox.

JQuery TableSorter click actions have no effect

I must be doing something stupidly wrong, but I'm not seeing it. On my site, I attach the JQuery TableSorter to a table and hope to have some sorting done, but clicks have no effect. No sorting happens. It just remains as a static table.
Here's a simplified JSFiddle of the problem I'm having:
http://jsfiddle.net/96AEE/3/
It's a very simple table with javascript as follows:
<table cellspacing="0" cellpadding="0" class="tablesorter" id="gift_certificates">
<thead>
<tr class="nav">
<td>
<input type="checkbox" onclick="checkAll();" class="short" value="1" id="check_all" name="check_all" />
</td>
<td>Gift Cert</td>
<td>Note</td>
<td>Order #</td>
<td>Order Date</td>
<td>Amount</td>
<td>Redeemed</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top"></td>
<td>ss1q</td>
<td>-</td>
<td>-</td>
<td>$300.00</td>
<td> Sale
</td>
<td>true</td>
</tr>
<tr>
<td valign="top">
<input type="checkbox" value="103" onclick="document.getElementById('check_all').checked = false;" class="short" id="check_103" name="check_103" />
</td>
<td>443ss</td>
<td>(1d10t) Arizona Tea</td>
<td>-</td>
<td>-</td>
<td>$50.00</td>
<td>-</td>
</tr>
<tr>
<td valign="top">
<input type="checkbox" value="50" onclick="document.getElementById('check_all').checked = false;" class="short" id="check_50" name="check_50" />
</td>
<td>199e</td>
<td>(#9000) Over</td>
<td>-</td>
<td>-</td>
<td>$300.00</td>
<td>-</td>
</tr>
<tr>
<td valign="top">
<input type="checkbox" value="87" onclick="document.getElementById('check_all').checked = false;" class="short" id="check_87" name="check_87" />
</td>
<td>F990</td>
<td>($09aa) Trouble</td>
<td>-</td>
<td>-</td>
<td>$300.00</td>
<td>-</td>
</tr>
</tbody>
</table>
JavaScript:
$(document).ready(function () {
$(".tablesorter").tablesorter();
});
Is there something obvious I'm missing?
This is due to your markup on the HTML table.
Within the thead element, you need to use th tags instead of td.
<thead>
<tr>
<th></th>
...
</tr>
</thead>
Working JSfiddle:
http://jsfiddle.net/bybFK/
Try changing your header row to use <th> tags instead of <td> tags.
You are definitely neglecting something, when creating the header of your table; your are using <td> instead of using <th>
you also do not need to assign the class tablesorter to your table
<table cellspacing="0" cellpadding="0" class="tablesorter" id="gift_certificates">
<thead>
<tr class="nav">
<th>
<input type="checkbox" onclick="checkAll();" class="short" value="1" id="check_all" name="check_all" />
</th>
<th>Gift Cert</th>
<th>Note</th>
<th>Order #</th>
<th>Order Date</th>
<th>Amount</th>
<th>Redeemed</th>
</tr>
</thead>
<tbody>
<tr>
<td valign="top"></td>
<td>ss1q</td>
<td>-</td>
<td>-</td>
<td>$300.00</td>
<td> Sale
</td>
<td>true</td>
</tr>
<tr>
<td valign="top">
<input type="checkbox" value="87" onclick="document.getElementById('check_all').checked = false;" class="short" id="check_87" name="check_87" />
</td>
<td>F990</td>
<td>($09aa) Trouble</td>
<td>-</td>
<td>-</td>
<td>$300.00</td>
<td>-</td>
</tr>
</tbody>
</table>
JavaScript:
$(document).ready(function () {
$("#gift_certificates").tablesorter();
});
http://tablesorter.com/docs/

Categories

Resources