Forum Moderators: phranque

Message Too Old, No Replies

passing data from forms to new windows?

javascript method for passing data to pop-up

         

aevea

2:15 am on Sep 2, 2003 (gmt 0)

10+ Year Member



Sorry if this is a stupid question or in the wrong place, but I'm very frustrated trying to do some javascript with a form. On one page I have a question with radio buttons and a submit button called "check answer". I'm opening a little pop-up for the answer, and want to pass the the response data to dynamically write parts of the new window depending on the response (right now I just have a generic answer).

I want to do it so I can use the same process for several questions (different htm's for each Q). I don't need to retain any of the data or use any database stuff.

If anyone could help I'd be very grateful.

txbakers

3:27 am on Sep 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main window has an object name of "opener" so, when you open the new window, any object on the main page is accessible by using the opener property:

if you have a form on the main page called "theForm" and an element called "radio1" you can read the value in the popup as follows:

var myAnswer = document.opener.theForm.radio1.value;

You can also set the values of form elements the same way.

HTH

aevea

5:18 am on Sep 2, 2003 (gmt 0)

10+ Year Member



Thanks, that helps, and I feel like I'm getting closer. But I'm still getting an undefined in my writeln. Do I need to do something special to grab the value of the checked button?

aevea

6:11 am on Sep 2, 2003 (gmt 0)

10+ Year Member



I think I got it, everything seems to be working. Here's the code

<h4>Credited Response: </h4>
<p>
<script language="JavaScript" type="text/javascript">
<!-- hide me
var answer
for (var i=0; i<opener.form1.rg1.length; i++)
{if (opener.form1.rg1[i].checked)
{answer = opener.form1.rg1[i].value}};
(answer == null)? document.writeln ("No answer ") : document.writeln ("While " + answer);
// show me -->
</script>
is a perfectly legitimate response, this question has no correct answer</p>

Thanks,
Adam