简体   繁体   中英

Using Javascript, how can I display form results in a popup window after being submitted?

I'm fairly new to Javascript. I'm trying to write a pretty basic program that will display the results of a form in a popup window after being submitted by the user.

I've got a form with all the relevant IDs. My problem is accessing this form from within the popup window. I've been playing around with window.opener.formid1 , window.parent.formid2 , document.forms[0] changing values where necessary, trying anything my countless searches have returned, but all I seem to get are "undefined" errors. I tried defining my variables in several different places but after a lot of testing I'm getting nowhere.

I'm aware you can use, for example

var popup = window.open("popup.html")
popup.document.write('')

which works fine but I don't want to overwrite the contents that are already in there and unless I'm mistaken, there isn't a way to append or edit a file.

If someone can offer a solution or any feedback, it'd be much appreciated. Thanks.

Have you tried: popup.document.getElementById('formID').appendChild . I beleive that should work.

If I understand it correctly, you are trying to submit your form and want to display the result in a new pop up.

If you want to submit your form and want to get the response use the AJAX which is again javascript. You can get AJAX examples from google for your assistance.

As you have already mentioned, writing on popup or sending value to the popup (may be through query string) would work after you receive the result from AJAX request.

From the popup, the following should work:

var form = window.opener.document.getElementById('formid1');
// Get data from form here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM