Hey there, I need help with trimming the leading spaces using JavaScript when the value is fetched from a database. I am using JSP tags to retrieve the value and load it into an input field. The issue I'm facing is that if there are any spaces at the beginning of the value, nothing gets displayed in the input fields.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script>
function getValue() {
<jsp:useBean id="ProjectBO"
class="com.nousinfo.tutorial.employee.service.model.bo.EmployeeProjectBO"
scope="request" />
document.getElementById("empNumber").value = '<jsp:getProperty property="employeeNumber" name="ProjectBO"/>';
document.getElementById("projectCode").value = '<jsp:getProperty property="projectCode" name="ProjectBO"/>';
document.getElementById("startDate").value = '<jsp:getProperty property="startDate" name="ProjectBO"/>';
document.getElementById("endDate").value = '<jsp:getProperty property="endDate" name="ProjectBO"/>';
document.getElementById("role").value = '<jsp:getProperty property="role" name="ProjectBO"/>';
}
</script>
</head>
<body onload="getValue()">
<form id="employee" action="ProjectUpdateServlet" method="post">
<table width="1254" height="74" border="0" align="center">
<tr>
<td width="970" height="68" align="center" bgcolor="#99CCFF"><h2>
<span class="style1">Project Detail</span>
</h2></td>
<td width="274" height="68" align="center" bgcolor="#FFFFFF"><img
src="/image/Emp.jpg" width="190" height="92" /></td>
</tr>
</table>
<p>
<br />
</p>
<hr size="1" width="786">
<table width="786" border="0" align="center">
<tr>
<td><input type="hidden" name="updateStatusProject" value="M" /></td>
</tr>
<tr>
<td width="298">Employee Number:</td>
<td><input type="text" id="empNumber" name="employeeNumber" readonly="readonly" />
</td>
<tr>
<td>Project_Code:</td>
<td><input type="text" name="projectCode" id="projectCode" readonly="readonly"/>
</td>
</tr>
<tr>
<td>Start_date</td>
<td><input type="text" name="startDate" id="startDate" /></td>
</tr>
<tr>
<td>End_date</td>
<td><input type="text" name="endDate" id="endDate" /></td>
</tr>
<tr>
<td>Role</td>
<td><input type="text" name="role" id="role" /></td>
</tr>
</table>
<p> </p>
<br />
<table width="200" border="0" align="center">
<tr>
<td><center>
<input type="submit" name="submit" value="Save" onclick="self.close()"/>
</center></td>
<td><center>
<input type="button" name="cancle" value="Cancel"
onclick="self.close()">
</center></td>
</tr>
</table>
<hr size="1" width="786">
<p> </p>
</form>
</body>
</html>