Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

POPUP

 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) I have a Struts action with some fields.
2) When a button press, I have to open a new Javascript popup window.
3) That window have "OK" and "Cancel" Buttons.
4) I want to submit the form if user press "OK" else i want to forward to another page.
5) I dont want to use javascript alerts. But popup window.

I think this is a regular problem. Anyone knows?.

Thanks
Basha
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not use the javascript confirm() method? It has both an OK and a cancel button and is ready-made for this type of operation. If you still don't want to use it, you can create a popup window using the window.open() method. You can then create an html page to be displayed in this new window with an Ok and Cancel button. In the on click method for your buttons, you can refer back to the window that opened the popup using the property window.opener.
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No way to use confirm().

I tried window.opener before posting here. javascript in new window(popup) cant recognize the form i use in the parent window. (document.parentwinowform.element[0].value or document.parentwinowform.myelement.value not displaying anyting and gives error). becoz it cant recognize that form.

How do u send the parameter(URL parameter) while creating JS popup window.Now i given full path(just for testing). Context relative path does'nt working(eg /myapp/mypopup.jsp).

what's the way to make JS(javascript)recognize my parent window form?.

Thanks for ur help.
Basha
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody may answer before i post the answer here?.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As I stated before, you must use window.opener to refer to any object in the window that opened the current document. In the example you gave, the reference would be: window.opener.document.parentwinowform.element[0].value. I know this works, because I use it often.

It is also possible to use a relative path to your jsp. It's the same as any other reference in a web application. The path is relative to the current page, so if the current page is in /myApp/, the reference would simply be "mypage.jsp"
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so if the current page is in /myApp/, the reference would simply be "mypage.jsp"

My context is

/mycontext.

The jsp in

/mycontext/jsp/myjsp

popup in

/mycontext/jsp/mypopup.jsp

When i give the path /jsp/mypopup.jsp, window is opening. But not getting reference to parent window form(window.opener.document.parentwinowform.myelement.value gives error).

If i use just "mypopup.jsp" or "/mypopup.jsp" as URL parameter, new window says URL does'nt exists. So it needs path from context path(rest of the path after context).

Any solution?.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please the portions of your main window you're trying to access, as well as the javascript code in the popup window you're using to access it, as well as the javascript error message you get when you try to run the code. This might help pinpoint what the problem is.

Also, here's a link the explains in greater detail how to use the "opener" property.

http://www.webreference.com/js/tutorial1/opener.html
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple!!. The actionform was renamed and i forgot that. LOL.

The problem was that i have previousely mentioned. window.opener does'nt reference to parent window. But that's becoz actionform was renamed. document.forms[0] works well. I dont touched JS for years. So i thought it can be a JS issue. Was not confident abt this loosely coupled language.

After playing sometime with JS, i started liking it. It's cool.

Good link. Thanks.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic