Link to home
Start Free TrialLog in
Avatar of MDEEPTI
MDEEPTI

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of fritz_the_blank
fritz_the_blank
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MDEEPTI
MDEEPTI

ASKER

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
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
Avatar of MDEEPTI

ASKER

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
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
Avatar of MDEEPTI

ASKER

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.....
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
Avatar of MDEEPTI

ASKER

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
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
Avatar of MDEEPTI

ASKER

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.

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
Avatar of MDEEPTI

ASKER

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
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
Avatar of MDEEPTI

ASKER

could u be more clearer???and will it work in netscape too??
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)
Avatar of MDEEPTI

ASKER

hi,
Thanks for the answer.I am sorry if i bugged u,but....
hurray!!!i got it.

Avatar of MDEEPTI

ASKER

thanks for the help,i really appreciate it.and u r some sort of genius i guess:)
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