Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Business Intelligence
  3. Question
Business Intelligence

Form validation isn't working when submitting it using Javascript

Asked by Angela Baker Jun 5, 2021 2.3K views 2 answers
Share

About this question

 I have a basic webform that calls a Javascript method after clicking on the submit button. The method applies some logic and when it's done, the form is submitted.

It seems that I can't force the user to fill up the form anymore, although I see the error flag appears for a split second, the form still submits even when it's empty. It ignores the 'required' attribute.

Form (snippet):

Form

<form method='post' id='prechatForm' autocomplete="on">
* <input type="text" name='liveagent.prechat:ContactFirstName' class="form-control" id="firstName" placeholder="John" required="true" autofocus="true"></input>
* <input type="text" name='liveagent.prechat:ContactLastName' class="form-control" id="lastName" placeholder="Smith" required="true"></input>
<input type='submit' class="btn btn-default btn-lg btn-outline" value='Chat Now' id='prechat_submit' onclick="setName();checkIfCaseExists()" />
JS method:
[removed] function checkIfCaseExists() { some remote logic................... document.forms["prechatForm"].submit(); return true; }
set 'action' attribute to form:
(function() { function handlePageLoad() { var endpointMatcher = new RegExp("[\?\&]endpoint=([^&#]*)"); document.getElementById('prechatForm').setAttribute('action', decodeURIComponent(endpointMatcher.exec[removed].search)[1])); } if (window.addEventListener) { window.addEventListener('load', handlePageLoad, false); } else { window.attachEvent('onload', handlePageLoad, false); } })();

when I use the regular functionality of the submit button, i.e. without calling any method on the way and then submitting, the validation works fine.


Your answer

2 Answers

Prerna Dixit Latest answer

Answered on Dec 1, 2025

The company of Jalandhar Escorts Service offers you the best of romance and desire all mixed in perfectly. Their sexually attractive involvement is what makes every moment the one to be remembered.


Was this helpful?

More Business Intelligence discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Business Intelligence Blogs

Guides, tips and career advice on Business Intelligence from JanBask experts.