Opening a popup on a text box click in Struts using javascript

About a week ago, while working on a project, I had the requirement of opening a popup window if a user clicks on a text box. I knew I would use JavaScript but didn’t know what to write and how to. I googled a bit and finally could create a popup. First of all I wrote the jsp page as :

<td><s:textfield name="txtUserName" label="UserName" readonly="true" value="%{#session['up'].userName.userName}" cssStyle="background:grey;" onclick="popitup('settings/popup.jsp')"></td>

Now coming to the JavaScript function, we can either create a different myjavascript.js page and link it in the heading section of the JSP page as:

<script type="text/javascript" src="myjsfolder/myjavascript.js"></script>

Otherwiese we can just include the function in


// Put javascript function here


Finally comes the JavaScript function that would do the work,

So here it is:

function popitup(url) {

var newwindow =, 'popup', 'width=250,height=200,top=100,left=100');


Simple its done , just click the textbox and the popup window should open. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s