I have this old javascript that works but now I need to change the layout to Bootstrap and I sort of copy it over. But, it is not working in html5 bootstrap layout!
Hope someone can tell me what is wrong.
<%@ page contentType="text/html; charset=UTF-8"%>
<html lang="en">
<head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title></title>
<!-- Bootstrap Core CSS -->
<link href="BootStrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="BootStrap/css/modern-business.css" rel="stylesheet">
<!-- Custom CSS - checkbox-->
<link href="BootStrap/css/checkbox.css" rel="stylesheet">
<!-- Custom CSS - options-->
<link href="BootStrap/css/bootstrap-multiselect.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="BootStrap/font-awesome/css/font-awesome.min.css"
rel="stylesheet" type="text/css">
<!-- Custom JavaScript -->
<link href="BootStrap/Checkbox.js" rel="stylesheet"
type="text/javascript">
<!-- Custom JavaScript -->
<link href="BootStrap/bootstrap-multiselect.js" rel="stylesheet"
type="text/javascript">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<script language="javascript">
function checkForm() {
// declare an empty Object variable.
var objForm = new Object();
var objFullNameTextBox = new Object();
var objMessageBox = new Object();
var objAddress = new Object();
objForm = document.getElementById("frmData");
objFullNameTextBox = document.getElementById("txtFullName");
objMessageBox = document.getElementById("divMessage");
objAddress = document.getElementById("txtAddress");
strName = objFullNameTextBox.value;
strAddress = objAddress.value;
if (strName == "") {
strMessageToUser += "Please indicate Name<br>";
blnIsAllOkay = false;
}
if (blnIsAllOkay == true) {
objForm.submit();
} else {
objMessageBox.innerHTML = strMessageToUser;
}
function trimData(pstrData) {
var intIndex = 0;
var intRightIndex = pstrData.length - 1;
while ((intIndex < pstrData.length) && (pstrData.charAt(intIndex) == ' '))
{
intIndex++;
}
while ((intRightIndex > intIndex) && (pstrData.charAt(intRightIndex) == ' '))
{
intRightIndex -= 1;
}
return pstrData.substring(intIndex, intRightIndex + 1);
}
}
function clearErr() {
objMessageBox = document.getElementById("divMessage");
objMessageBox.innerHTML = "";
}
</script>
And then in my html5 bootstrap template I have:
<div class="control-group form-group">
<div class="controls">
<label>Full Name:</label> <input type="text" class="form-control"
id="txtFullName" name="txtFullName" required name="name"
data-validation-required-message="Please enter your name.">
<div id="success"></div>
<!-- For success/fail messages -->
<button type="submit" id="btnSubmit" name="btnSubmit" onclick="checkForm" class="btn btn-primary">Submit</button>
</form>
However, when I left the name textbox blank, it doesnât give out the error message: Please enter your name when I hit the submit button.
Hope someone can tell me what is wrong. Cos I am not sure if I can combine the old javascript on the new html5 bootstrap layout.