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" >
<script type="text/javascript">
(function() {
function handlePageLoad() {
var endpointMatcher = new RegExp("[\\?\\&]endpoint=([^&#]*)");
if (window.addEventListener) {
window.addEventListener('load', handlePageLoad, false);
} else {
window.attachEvent('onload', handlePageLoad, false);
<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" />

You may want to read more about Jquery Validator, you can find the same here
Generally, you'll need to attach an event handler to your input fields. Something like:

<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.