Solved

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

Posted on 2004-08-20
13
404 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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
 

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…

840 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