You need to sign in to do that
Don't have an account?

Making Form Fields Reqiuired in VisualForce
I am trying to make a set of text fields in a form required in a VisualForce page. I was told to use Javascript for this, specifically the checkField function but I am not sure how this is structured. Below is my form. Thank you everyone!
<apex:page showheader="false" >
<html>
<head>
<script type="text/javascript">
(function() {
function handlePageLoad() {
var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
document.getElementById('prechatForm').setAttribute('action',
decodeURIComponent(endpointMatcher.exec(document.location.search)[1]));
}
if (window.addEventListener) {
window.addEventListener('load', handlePageLoad, false);
} else {
window.attachEvent('onload', handlePageLoad, false);
}
})();
</script>
</head>
<body>
<form method="post" id="prechatForm">
<!-- Detail inputs -->
First Name: <input type="text" name="liveagent.prechat:First Name" id="First_Name__c" /><br /><br />
Last Name: <input type="text" name="liveagent.prechat:Last Name" /><br /><br />
Dealership Name: <input type="text" name="liveagent.prechat:Dealership Name" /><br /><br />
<input type="submit" value="Request Chat" id="prechat_submit" />
</form>
</body>
</html>
</apex:page>
<apex:page showheader="false" >
<html>
<head>
<script type="text/javascript">
(function() {
function handlePageLoad() {
var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
document.getElementById('prechatForm').setAttribute('action',
decodeURIComponent(endpointMatcher.exec(document.location.search)[1]));
}
if (window.addEventListener) {
window.addEventListener('load', handlePageLoad, false);
} else {
window.attachEvent('onload', handlePageLoad, false);
}
})();
</script>
</head>
<body>
<form method="post" id="prechatForm">
<!-- Detail inputs -->
First Name: <input type="text" name="liveagent.prechat:First Name" id="First_Name__c" /><br /><br />
Last Name: <input type="text" name="liveagent.prechat:Last Name" /><br /><br />
Dealership Name: <input type="text" name="liveagent.prechat:Dealership Name" /><br /><br />
<input type="submit" value="Request Chat" id="prechat_submit" />
</form>
</body>
</html>
</apex:page>
Input
JS Function
Or you can use a library which will each have their own way of doing it, i.e. above.