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
<script>
// Put javascript function here
</script>
Finally comes the JavaScript function that would do the work,
So here it is:
function popitup(url) {
var newwindow = window.open(url, 'popup', 'width=250,height=200,top=100,left=100');
}
Simple its done , just click the textbox and the popup window should open. 🙂