Struts 2 button onclick function call

Struts 2 button onclick function call

Here you will see how to call JavaScript function when click button on JSP page in struts 2 application. Please find details below:

  • onclickFunctionCall.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
<%@ taglib prefix="s" uri="/struts-tags"%>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<title>Struts 2 button onclick function call</title>
<link rel="stylesheet"
    href="//" />
<script type="text/javascript"
<script src="//"></script>
<script type="text/javascript">
    function onButtonClick(){       
        var firstName = $('#firstName').val(); 
        var lastName = $('#lastName').val(); 
        alert("First Name: "+firstName+" Last Name: "+lastName);           

<s:head />

    <h2 style="color: green">
        <s:text name="Struts 2 button onclick function call" />
    <s:form action="" namespace="/" method="post"
        <s:textfield id="firstName" size="30" maxlength="50" label="First Name" value=""/>
        <s:textfield id="lastName" size="30" maxlength="50" label="Last Name" value=""/>
        <s:submit type="button" label="Button onclick function call" onclick="onButtonClick();return false;"/>          




Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *