Arun Sudhakaran Arun Sudhakaran - 1 year ago 69
Javascript Question

How to avoid confirmation message from browser when form is submitted at onclick event of a span?

This is the initial state of the JSP page, with one set of data looks like this

enter image description here

If the client clicks on the + icon or Click here label the form should be submitted and the list will be increased which will look like

enter image description here

The form submission is proper when + icon is clicked, but when Click here label is clicked the browser is asking a confirmation message

enter image description here

The JSP code portion is :-

<table width="100%" cellspacing="1" cellpadding="2">
<td align="center">
<span style="cursor: pointer;" onclick= "addEvaluators('addEvaluators')">
<font color="#228B22">Click here</font>&nbsp;
<img src="images/admission/images/12673199831854453770medical cross" width="20px" height="20px" style="vertical-align:middle;">
to increase evaluators
<logic:equal name="paperEvaluationUpdateEntryForm" property="showRemoveButton" value="true">
<td align="center">
<span style="cursor: pointer;" onclick="removeEvaluators('removeEvaluators')">
<font color="#B22222">Click here</font>&nbsp;
<img src="images/admission/images/15107-illustration-of-a-red-close-button-pv.png" width="22px"; height="22px"; style="vertical-align:middle;">
to decrease evaluators

The Javascript code I wrote is :-

function addEvaluators(method) {

The reason why I kept both the image and label inside a span tag is because I want the form to be submitted at the onclick event of both and font tag is not having an onclick event.

My question is why that confirmation message is coming when the label is clicked, which is not happening when the image is clicked, and how to avoid it?

Answer Source

You can add below code in onSubmit method


This will skip alert function.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download