``There is an issue with the onsubmit property that prevents the opening of

I have encountered an issue with my forms that has me stumped. Despite searching online for help, I can't seem to figure out why my implementation is not working as intended.

The concept is straightforward. I've embedded a form within a JSP page. The form includes an 'onsubmit' property that is supposed to trigger the opening of a different JSP file along with some parameters. Additionally, there are buttons inside the form, one of which invokes a JavaScript function responsible for submitting the form under specific conditions.

Below is the relevant code snippet: JSP:

...
<form id='testForm' onsubmit="window.open('another.jsp')">
  <input type="button" onclick="callJsFunction()" />
  ..
</form>

JavaScript:

function callJsFunction() {
  if (launchNow == 1) {
    var form = document.getElementById("testForm");
    form.submit();
  }
}

Adding target="_blank" to the form definition opens a new window, but not the desired JSP file. My end goal is for the form to execute a servlet action (using the action attribute) and then display the new JSP file. Any suggestions or insights would be greatly appreciated!

Thank you!

Answer №1

I finally found the solution I was searching for right here: Opening a New Window on Form Submit with JavaScript

Instead of using target="_blank", I learned that I can set a specific window as the target to open. By redirecting to the desired jsp in my servlet, it now displays in a new pop-up window exactly as intended.

Answer №2

<form id='registrationForm' action='submit.php' target='_blank'>

Answer №3

Perhaps this is what you're searching for?

Take a look at the live demo by clicking on this link: http://fiddle.jshell.net/vf6AC/show/light/ (please note that it does not work in jsfiddle)

<form action="http://google.com" id="testForm">
    <input type="submit" />
</form>

<script type="text/javascript">
var testForm = document.getElementById("testForm");

testForm.onsubmit = function(e){
    window.open("http://stackoverflow.com");
    
    return true;
};
</script>

You can view the jsfiddle here: http://jsfiddle.net/vf6AC/

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

Implementing a Singleton Pattern in ReactJS using Context API for Asynchronous Operations

My current implementation involves using a hook: function useFollowUser() { const isFollowing = useRef(false); return (userId) => { if(isFollowing.current) return; // mutual exclusion isFollowing.current = true; ... updat ...

Looking for a way to efficiently sort through props in Next.js? Struggling with filtering data within props from componentDidMount in Next.js?

I retrieve data into the props of my component using getStaticProps. However, I need to filter this data before utilizing it in the component. Typically, I would do this in componentDidMount, but it appears that the props are populated after componentDidMo ...

What is the best way to submit form data along with an image using Angular?

Recently, I built an application where users can submit form data along with an uploaded image. Since I am new to Angular, I am facing some challenges in merging the user-submitted data model and the image upload using the FormData method. Can anyone guide ...

Nodemon fails to restart: [nodemon] attempting restart because of modifications

I ran the command: npm run server Despite my attempts to find a solution, I am still puzzled as to why the results are not working. Even after globally installing npm install -g nodemon, the server still does not restart automatically and only displays me ...

Encountering an error while trying to update a field using the $inc operator in

Currently, I am working on updating a field in my database to increment it each time like a counter. This will allow me to consistently receive the latest values. To achieve this, I have defined the following schema: var CounterSchema = new Schema({ _id: ...

Utilize a select box to toggle between enabling and disabling options

Could someone please help me with enabling and disabling a text field based on a select box option? I'm not sure if I have written the code correctly below. If there are any errors, please correct me. <body> <table width="500" border="1"> ...

Utilizing React to invoke the filter method on Object.keys

A specific React component receives a state property that consists of nested objects: { things: { 1: { name: 'fridge', attributes: [] }, 2: { name: 'ashtray', ...

Steps for bundling a Node server with an Electron application

I am looking to package my Electron app, built with React.js, along with a local Node server into a single executable file. Is there a way to ensure that the separate Node server runs simultaneously with the Electron app when the program is executed? ...

E/AndroidRuntime: CRITICAL ERROR: main --- java code in an android app

I've been working on a map application and I've run into some issues. Can anyone help me figure out what's wrong with my code? ERROR 10-25 01:37:41.296 28673-28673/com.onemap.activities E/AndroidRuntime: FATAL EXCEPTION: main 10-25 01:37:4 ...

What causes CSS to fail to load in React but work normally in Next.js?

We are currently experiencing an issue with a component located in a Git Submodule that is being used by both Next.js and React. While everything is functioning correctly in Next.js, React is unable to accept the way the CSS is being loaded: import styles ...

Guide on positioning a span element to the left using the margin auto property in CSS for Angular 4

Having trouble with moving numbers highlighted to the left with names in CSS. I've tried using flex direction and margin auto but can't achieve the desired result. Here is my HTML code: <section class="favorites"> <div class="category" ...

Concealing and revealing the triangular indicator within a bullet diagram using the AngularJS-nvd3-directives library

I am currently utilizing the nvd3-bullet-chart feature from the angularjs-nvd3-directives library in order to present maximum, current, and average data. To exclude the minimum variable from the array for display purposes, I have set its value to 0. In a ...

Mastering the art of utilizing v-if and v-for with nested objects in Vue.js

Struggling to display nested object content using v-for. I have a prop containing an object, but the div doesn't show when I use v-if="prop". Any help on how to resolve this issue would be greatly appreciated. Below is the syntax I'm currently us ...

Troubleshooting: Why is my switch-case statement in TypeScript not functioning as expected

Here is a simple switch case scenario: let ca: string = "2"; switch (ca) { case "2": console.log("2"); case "1": console.log("1"); default: console.log("default"); } I am puzzled by the output of this code, which is as follows: 2 1 defa ...

Utilizing VUE with Socket.io or vue-socket.io Integration

I've been working on connecting using socket.io (client) and websocket.org (server) with vue.js. Despite going through all the examples, I can establish a connection to the socket but when I emit the event BOARD_ID, I don't receive any response. ...

Guide on downloading jsreport in .Net using C# without opening it

I am using JS Report to generate a file and save it in the root directory. However, I want the file to be downloaded directly instead of opening for viewing. var header = await _jsReportMVCService.RenderViewToStringAsync(HttpContext, RouteData, "H ...

Exploring ways to retrieve global variables within a required() file in Node.js

Imagine having 2 files: main.js, and module.js: //main.js const myModule = require('./module'); let A = 'a'; myModule.log(); //module.js module.exports = { log() { console.log(A); } } After trying to call myModule.log, ...

SystemJS could not locate the root directory for RxJS

There seems to be an issue with SystemJS loading rxjs modules on Windows, as it throws a 404 Not Found error on the rxjs directory. This problem does not occur on OSX, and all modules are up to date. GET http://localhost:8080/node_modules/rxjs/ 404 (Not F ...

React.js not displaying image

Here's my App.js File I am trying to display an image from the MongoDB database. Click here to view the image stored in MongoDB The images are stored as Binary data in MongoDB How can I display the image on the React page? import React,{useState} fr ...

Validation in ASP.Net to ensure the correct number of days between the arrival and departure dates

One of my project requirements involves checking the validation of the number of days entered between two date selectors (From & To Dates). The constraint is that the difference should not exceed 100 days. I'm considering using ASP.NET validators for ...