Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

submitting form on calling window from code in child window

Status
Not open for further replies.

RobBroekhuis

Technical User
Oct 15, 2001
1,971
0
0
US
I have a "preview" window (opened by my main window), on which there is a button to "submit" the information. The form to submit is on my main window. I thought the following should work:

<form onSubmit=&quot;window.close()&quot;>
<input type=&quot;submit&quot; value=&quot;close and edit&quot;>
<input type=&quot;submit&quot; value=&quot;submit&quot; onClick=&quot;opener.document.forms['SubmitThread'].submit()&quot;>
</form>

But it doesn't. Both buttons merely close the preview window. The form is properly addressed (I can alert the value of a field on the form just fine), but the submit method doesn't trigger. If it matters - the form has an onSubmit clause that triggers a Javascript form validation routine.
What am I doing wrong?


Rob
[flowerface]
 
Why don't you eliminate the &quot;onsubmit = window.close()&quot; and instead add it to the onclick event

<form>
---type here whtever text and html you need---
<input type=&quot;button&quot; value=&quot;submit&quot; onClick=&quot;opener.document.forms['SubmitThread'].submit(); window.close()&quot;>
</form>
 

Just a reminder, users can also press the enter key that can cause the form to submit. Under such cases, the onClick action would be ignored. It may be better to put the calling just at

<form onSubmit=&quot;opener.document.forms['SubmitThread'].submit(); window.close();&quot;>

rgds,
Nickson
 
The form is set up such that the user can click two buttons - one to go back and edit, the other to submit the form. In both cases, the child window will close - that's why the close action is in the form's onSubmit clause. In the case of the close button (go back and edit), that's the only thing that needs to happen. In the case of the submit button, the form also needs to be submitted. I think it would be cleaner to FIRST close the child window and THEN submit the form, but I don't know how to have to trigger the submit after the child window closes.
So - I still need help!


Rob
[flowerface]
 
Bob, did you try using my suggestion? It will work. You will have to do the submitting first before closing. The closing will be instantaneously executed after the submitting the parent form.

For your other edit button, you will simply just put another javascript onclick action such as

opener.location = &quot;xxx.asp&quot;;
window.close();

That should settle for everything u mentioned.

rgds,
Nickson
 
Nickson,
Thanks for the follow-up. Actually, I tried your suggestion but it did not work. I've been remiss in not following up here with the answer that worked for me (which I got from a DevShed forum): what I needed to do was rename the submit button on my main page to something other than &quot;submit&quot;. JS was misinterpreting my method call because I had a form element by the same name.
Cheers


Rob
[flowerface]
 
Rob...

Wish I'd read your initial post 2 days ago... we had a rash of these &quot;mis-named&quot; submit buttons... and the threads in this (and the HTML) forum are probably still active.

I made this mistake once before too... took me ages to find the solution... and I've never made it since. Amazing how some things stick in your head like that.

Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top