Solved

JavaScript write the data from pop-up form back to main.asp

Posted on 2004-08-20
13
401 Views
Last Modified: 2008-02-01
Hi Experts,

Below is what I am trying to accomplish:

I have main.asp and pup.asp. There is an Textbox "Email" and a "Add email" link next to the Textbox on main.asp. If the user click "Add email" link, it will pup-up pup.asp which ask user to check-mark from an email list. once it is done, the user click on 'Submit button' on pup.asp and the value will be write back to the Textbox "Email" in main.asp.

The following is the code for check-box in pup.asp:
"  <TD><INPUT TYPE='checkbox' name=""chk_"&rsItems1("EmailAddr")& """ value= "&rsItems1("EmailAddr")&">" & _
       
                "</TR>"

once the user click on submit button on pup.asp, it will go to "AddEmail.asp", below is the code for "AddEmail.asp":
<script language=javascript>

self.opener.frmUser.noticeemail.value='<%=chk_%>'
self.close()
</script>

frmUser is the form name for main.asp. noticeemail is the name of the Textbox in main.asp.


It won't write anything to Textbox now.

Thanks in advance!
0
Comment
Question by:mrong
  • 5
  • 4
  • 2
13 Comments
 
LVL 2

Expert Comment

by:rabanero
ID: 11850973
You have to replace noticeemail object into frmUser form, with:

<input type="hidden" name="noticeemail" />

Nothing appears in the screen, but value returned by pup.asp will be saved and sent in frmUser submit.
0
 
LVL 3

Expert Comment

by:mattfairw
ID: 11850983
window.opener.document.frmUser.DateFieldName.value = TheDateSelectedOnThePopUp
0
 

Author Comment

by:mrong
ID: 11850992
My bad, the Textbox is "noticeemail" on the main.asp
I want the Textbox "noticeemail" display on the main.asp

Thanks.
0
 

Author Comment

by:mrong
ID: 11851003
mattfairw,

Could you pls use the name which I used in the code?
Thanks.
0
 
LVL 2

Expert Comment

by:rabanero
ID: 11851016
I don't understand. Sorry :(
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:mrong
ID: 11851033
Can I write the data back to Textbox "noticeemail"(main.asp) from pup.asp?

I have Textbox "noticeemail" on the main.asp already.

Thanks.
0
 
LVL 3

Expert Comment

by:mattfairw
ID: 11851213
in the popup, after the user has selected the date you wish, you would call the form element by name just like you would if you were on the main page, but tack on "window.opener" at the beginning. So:

window.opener.document.frmUser.noticeemail.value = TheDateSelectedOnThePopUp

-Matt
0
 

Author Comment

by:mrong
ID: 11851242
SHouldn't it be self.opener.frmUser.noticeemail.value='<%=chk_%>'?
I changed to self.opener.document.frmUser.noticeemail.value=chk, but the form didn't submit.
0
 
LVL 3

Accepted Solution

by:
mattfairw earned 100 total points
ID: 11851335
well if each checkbox has a value, you would assign to the main form the value that was clicked. You would only use the ASP if you were going to reload the main page by passing it a query string, have the popup have an onSubmit function that will check the popup form for the email checked, and send that back to the main page like:

var numCntrls = document.popUpFormName.length;
var cntrlIndex, element;

for (cntrlIndex = 0; cntrlIndex < numCntrls; cntrlIndex++)
{
  element = document.popUpFormName[cntrlIndex];
  if (element.type == "checkbox")
    if (element.checked)
    {
      window.opener.frmUser.noticeemail.value = element.value;
      window.close();
    }
}

-Matt
0
 

Author Comment

by:mrong
ID: 11851989
I don't want to reload the main.asp coz the user might have already edit some data in main.asp and I don't want them to lose it. Is it possible to do?
0
 
LVL 3

Expert Comment

by:mattfairw
ID: 11853953
the code i gave you does not reload the main page. it is all javascript
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now