What can I do to prevent the second onclick function from running while the first function is in progress?

I am currently in the process of developing a validation feature for my project. In case the form fails to validate, it should not be able to submit. Therefore, I am looking for a solution to prevent the function submitFilloutform() from executing.

<button 
  id="submit" 
  name="submit"
  type="submit"
  class="btn btn-warning"
  style="float: right;"
  onclick="validateForm(), submitFilloutform()"
>Submit</button>

Any assistance on this matter would be greatly valued. Thank you!

Answer №1

UPDATE: I revisited this post after receiving an upvote (thank you). It's worth mentioning that using inline JS can pose a security risk in terms of potential cross-site scripting attacks. One way to mitigate this risk is by implementing Content Security Policy (CSP) headers, with one effective measure being the prohibition of all inline JS. Therefore, if you are considering CSP implementation, it might be advisable to refactor the JS code provided into an onclick listener for id=submit within a separate external JS file.

Original response.

The onClick attribute allows for JavaScript logic to be included and executed like a function. For example...

<button 
  id="submit" 
  name="submit" 
  type="submit"  
  class="btn btn-warning" 
  style="float: right;" 
  onclick="if (validateForm()){ submitFilloutform();}"
>
Submit
</button>

This snippet assumes that validateForm() returns a boolean value.

Answer №2

Is there a reason for not calling the second function within the first function's block?

<button 
  id="submit"
  name="submit"
  type="submit"
  class="btn btn-danger"
  style="float: right;"
  onclick="validateForm()"
>Submit</button>

function validateForm() {
  // xxx
  performSubmission()
}

function performSubmission() {
  // xxx
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

ExpressJS Template Caching System

Encountering issues with template caching in my MEAN app. The navigation bar uses conditional logic to show/hide buttons based on user status. Upon page load, values are null or false until login (views, isLoggedIn). The problem arises post-login - despit ...

What methods is Facebook using to manage their onbeforeunload confirmation dialog?

While using Facebook on the latest Chrome browser on my Mac, I observed an interesting behavior. When I began typing in a comment box and then clicked on another link or pressed the back button, a confirmation window popped up asking if I wanted to leave: ...

The JQuery scroll function is not triggered right after a page refresh

Recently, I encountered an issue with my jQuery function that is designed to keep a div at the top of the page after scrolling beyond its original position. Strangely, following a button click (postback), the functionality seems to break and requires users ...

Allow removal of input masks upon successful submission

At the moment, I am utilizing this script to remove my masks upon submission: $(".active_validator").submit(function() { $('.money_mask').unmask(); $('.num_mask_thou').unmask(); $('.zipcode').unmask(); $(&apos ...

Is it possible to efficiently update the innerHTML of multiple div elements using a single function?

Upon clicking a button, I am dynamically updating the content of multiple divs using innerHTML. Currently, the button triggers a new video source to load, but I also want to change other types of content in different divs at the same time. I wonder if cha ...

What purpose does the by.js locator serve in Protractor/WebDriverJS?

Recently, I've come across a new feature in the Protractor documentation - the by.js(): This feature allows you to locate elements by evaluating a JavaScript expression, which can be either a function or a string. While I understand how this locat ...

Can someone show me how to code a function that transforms my paragraph into an image when I hover over it?

< p id="p1" onmouseover="this.style.color='transparent';flipPara()"> < p id="p2" onmouseover="spookyPara()"> function spookyPara() { document.getElementById("p1").attribute = "All_Images/ghost.png"; } I currently have this code sn ...

What is the best way to add a radial pattern to a ring using three.js r67?

I am facing a challenge in applying a texture to a ringGeometry using three.js r67. The issue lies in orienting the texture correctly. My goal is to apply a specific texture to a ringGeometry mesh in a radial manner, where the blue end of the texture align ...

What is the process for including "onload" in my Dojo class?

Is there a way for me to incorporate an "onload" function into my personalized Dojo class which can trigger functions that are registered to listen for the event? Perhaps something like myWidget.addOnLoad(...) My class doesn't belong to Dijit, it&apo ...

Having issues with Firefox rendering JavaScript and CSS correctly

I'm trying to figure out if it's the row class from Bootstrap that's causing issues, or if there's a problem with my JS/CSS not loading properly in Firefox. It seems to be working fine in Chrome and Safari. Any ideas on what could be go ...

Is there a way to link multiple GET requests and combine their results into an array in JavaScript/Node?

The current code is a bit messy, and I'm still unsure about the then method. What each 'get' call returns: An array with some, but not all, results. What I need: To pass two different URIs, concatenate the results of both, and then expor ...

Heroku Internal Server Error with NextJs version 5.0.0

Below are the scripts that I am using: "scripts": { "dev": "node server.js", "build": "next build", "start": "NODE_ENV=production node server.js", "heroku-postbuild": "next build" }, This is the content of my procfile: web: npm start ...

Is there a way to swap out values in a JavaScript Object for new ones?

I need to update the initial values of myObject with new names: let myObject = [ { name: 'X0', values: 'FALSE,TRUE' } , { name: 'X1', values: 'NORMAL,LOW,HIGH' } , { name: 'X2', values: ' ...

JS call for Bootstrap 5 collapse toggle not functioning as expected

I'm exploring the use of JavaScript to display or hide a collapsible element without toggling between the two states. In other words, I want to prevent the toggle functionality. According to the information provided in the documentation at https://ge ...

File resolution issue with TypeScript

While I am aware that using TypeScript outFile is generally advised against, I currently have no choice but to utilize it until a more suitable solution like AMD can be implemented. It seems like there may be a "module splitting issue" in my project. In t ...

Efficiently loading an image in one go

Rendering approximately 3000 records, each row displays: Customer Profile Edit Customer Name, Action 1 John Edit image | Delete image 2 John Edit image | Delete image 3 John Edit image | Delete image 4 John ...

Tips for implementing an active class for td within jQuery tabs?

I'm currently using Jquery tabs within a table, and it's working fine. However, I need to activate the td when its link is clicked. Here's my code: $(document).ready(function() { $(".vertical_tabs_menu a").click(function(event) { ...

Switch Cursor on Movable Area in Electron

Working on a project in Electron and having some trouble with a frameless window. I have designated certain top areas as draggable using -webkit-app-region: drag, but the cursor will not change as expected. Although this code snippet won't make the e ...

The dimensions of the canvas are directly impacting the stretching of the Sprite

I am currently working on a small program to render sprites with 2D transformations. You can find the project here. The issue I am encountering is that when trying to render a 100px by 100px square, it ends up being stretched into a rectangle shape. I have ...

Executing PHP code from a list item

On one of my website pages, I have a list that functions as a delete button. However, I am interested in making it so that when a user clicks on the delete option, a php script is triggered - similar to how a submit button works. Below is the list structu ...