function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Matt VirgilioMatt Virgilio 

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>
Avidev9Avidev9
You may want to read more about Jquery Validator, you can find the same here  http://jqueryvalidation.org/
tsalb_tsalb_
Generally, you'll need to attach an event handler to your input fields. Something like:

Input
<input type="text" onblur="checkThisField(this.value)">
JS Function
function checkThisField(value) {
  // Do some validation on value, being passed here
}
Or you can use a library which will each have their own way of doing it, i.e. above.