?
Solved

to submit the form from child window to file in parent window and pass javascript variable

Posted on 2003-03-24
18
Medium Priority
?
300 Views
Last Modified: 2008-03-06
i have a parent window with some jsp code
this is followup.jsp
<script>
window.name="wind"
</script>
<body>
<input type="button" onClick="window.open('win.jsp?fldref='+this.name,'child','height=100,width=500,resizable')">



following is win.jsp

in child i have

<form name="form1" method="post" action="followup.jsp" target="wind" onSubmit="window.close()">
<script>
like=location.href.substr(location.href.lastIndexOf('fldref=')+7);
document.write("
like:"+like);
window.document.form1.bname.value=like;
document.write("
name:"+window.document.form1.bname.value);
</script>
<input type="hidden" name="bname">
<input type="submit" name="Submit" value="Submit">

but i am unable to get the followup.jsp in the parent window....
and I am unable to pass the javascript value back to the parent window.
please suggest me a method...as soon as possible

0
Comment
Question by:MDEEPTI
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 9
18 Comments
 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 80 total points
ID: 8203547
This should help you:

************
main.htm
*************

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function openPop(){
     var winPop = window.open("popup.htm","winPop","width=200,height=200");
}
//-->
</SCRIPT>
</HEAD>
<BODY onLoad=openPop()>
<FORM action="" method=POST id=form1 name=form1>
<TEXTAREA rows=2 cols=20  name=strTextAreaText></TEXTAREA>
</FORM>
</BODY>
</HTML>


**********
popup.htm
**********

<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT LANGUAGE=javascript>
<!--
function populateHidden(strText){
     window.opener.document.forms[0].strTextAreaText.value = strText;
     window.close();
}
//-->
</SCRIPT>


</HEAD>
<BODY>
<FORM action="" method=POST id=form1 name=form1>
<TEXTAREA rows=2 cols=20 id=textarea1 name=textarea1>
</TEXTAREA>
<INPUT type="button" value="Return to Main" id=button1 name=button1 onClick=populateHidden(this.form.textarea1.value)>
</FORM>
</BODY>
</HTML>


Fritz the Blank
0
 

Author Comment

by:MDEEPTI
ID: 8204697
hi,
thanks for ur code,but I want the variable to be passed to the parent window so that the parent window can store it in session variable.could u suggest some alternative.

thanks
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8204776
Well, once the value is stored in a hidden field, you can then post the form, and then set the sesssion variable by using the request object. There is no real way to set a server-side variable from client-side code without a trip to the server.

Fritz the Blank
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:MDEEPTI
ID: 8204924
hi,

I have a requirement where i need to enter data from the user when a user clicks a button on the page and display the data which the user entered in the same page...I need to check the validity of the data and also need to store it in a session variable later....


how can i do it?? pls help me
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8205089
You are asking a lot here, but not providing the detail that I need to help.

My code above shows you how to pass the data from the child to the parent. I have also told you how to pass the data from your form to your session variable.

What is it exactly that you need help with at this point?


Fritz the Blank
0
 

Author Comment

by:MDEEPTI
ID: 8205233
hi,
i am novice in web development so plz help me...

in main.htm i changed the following

<BODY onLoad=openPop()>
<FORM action="" method=POST id=form1 name=form1>
<input type="hidden" name="strTextAreaText" value="hi">
<script>
document.write("<br>hi:"+this.form1.strTextAreaText.value);
</script>
</FORM>

but i was unable to get the updated value when i entered the data in popup window.could u tell me the reason.....
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8205311
Sure, because the document.write takes place before the updated value is called. If you want to see the value, use the following:

function showValue(strFieldName){
   alert(document.forms[0].elements[strFieldName].value);
}

and then call it like this:
<input type=button value="Show Hidden" onClick=showValue('strTextAreaText')>

Fritz the Blank
0
 

Author Comment

by:MDEEPTI
ID: 8205615
hi,

Thanks for ur replies.
I am sorry if I was unable to express myself clearly....
I have a main window which will pop up a new window.In  the new window the user enters data and will submit it..
The data entered by the user should be updated in the main window and the new pop up window should be closed...i am using jsp files here...


The popup-window contains a form  like this:

<form action="mainfile.jsp" target="main" method="post">
....
....

ie: it points back to the mainfile and to the window(main) that opened the popup-window. The problem here is closing the popup-window after form-submission.

onSubmit="self.close()" in popup form but its not working.could u tell me the reason
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8205689
Don't use the submit function! Look, please take a few minutes to study the example I gave you above. It will work exactly the way that you need it to. Save the files as main.jsp and popup.jsp if you need to (of course, you will have to change the code a little bit) but the idea is exactly the same.

Fritz the Blank
0
 

Author Comment

by:MDEEPTI
ID: 8205837
hi fritz,

thanks for ur reply..i really appreciate it.....
can u please tell me if i can display the updated contents of hidden tags in the main window and in some desired location (may be in a table) without the need to press the button to display them in an alert box.
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8205872

Well, then they wouldn't be hidden, right?

The very first example I provided shows the updated content without an alert box. The alert box was there only to prove to you that the data in the field had changed--you don't need it for things to work.

Fritz the Blank
0
 

Author Comment

by:MDEEPTI
ID: 8206146
hi,
thanks for the answer....
i think my problem of getting data is answered.But,to display data on the main window i need to find a way.If the solution u proposed is used, i will get data in the text box in the main window.I can disable the textbox but is there any way to prevent the user from realising that it is a text box.
deepti
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8206184
You could try creating a div and set the text for the div to that of the text box. The textbox could then be a hidden field so that you can pick up the value with the request object when you post the form.

Fritz the Blank
0
 

Author Comment

by:MDEEPTI
ID: 8206311
could u be more clearer???and will it work in netscape too??
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8206350
Okay, look. I have already answered your first question, and now you seem to be piggy backing a new question on to the old one. Please close this question out and post a new question regarding how to display the content of a hidden field in a div tag.

Fritz the Blank

P.S. Don't forget to take a look at EE guidelines for question points:

 This question is urgent or extremely difficult(500 points)
 This question is important or difficult(250 points)
 This question is not important and moderately difficult(125 points)
 This question is not important and easy(50 points)
0
 

Author Comment

by:MDEEPTI
ID: 8206491
hi,
Thanks for the answer.I am sorry if i bugged u,but....
hurray!!!i got it.

0
 

Author Comment

by:MDEEPTI
ID: 8206506
thanks for the help,i really appreciate it.and u r some sort of genius i guess:)
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 8206530
No, just a part-time fiddler.

If people seem a little short here, you should know that we are all volunteers and attempt to help others out in our spare moments.

Good luck with your project,

Fritz the Blank
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question