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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send Radio Section back to opener

Status
Not open for further replies.

PSFMIS

MIS
Feb 3, 2006
28
US
I'm sending a for text field back to a parent window like this:

opener.document.Form1.txtField1.value = MainForm.txtField1.value;

I also want to send a Radio button selection back... I have not been successful. Could someone help?

Thanks,
Aaron
 
Have you tried "parent" instead of "opener"?

Also: "document.MainForm." instead of just "MainForm."

Radio buttons make up an array (all the buttons of the same name are in it). For example, if you have three buttons as so:

Code:
<input type='radio' value='Yes' name='Answer' />Yes
<input type='radio' value='No' name='Answer' />No
<input type='radio' value='Yes' name='Answer' />Maybe

...then, in your JavaScript, you need to cycle through them to find which is checked:

Code:
for(var i=0; i<document.MainForm.Answer.length; i++)
{
 if(document.MainForm.Answer[i].checked)
 {
  parent.document.Form1.someElement.value = document.MainForm.Answer[i].value;
  break;
 }
}

Tell us more... Is the "lower" page inside an IFRAME or in a window of its own? ...or did it open in the same window as the page that called it (in which case, you will need to take a very different approach!).

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
I should clarify. I want to send the radio selection upon clicking a form Submit button rather than onclick for each radio selection. Is this possible?

Do I have to use onclick to send the value of each radio button when its selected?

Or is ther something like this:
opener.document.Form1.txtField1.value = MainForm.txtField1.selectedValue;

-Aaron
 
I'm new to javascript so that for loop looks a little strange to me.. It's looks like what I had in mind if there was no MainForm.RadioFrom1.selectedValue or anything like that to use.

-Aaron
 
Could you explain this like to me?

for(var i=0; i<document.MainForm.Answer.length; i++)

-Aaron
 
Well, if the Submit button is in the "lower" page, you can include an onclick event in the button which calls a function on that page which evaluates the value of the checked radio button and sends that back.

SELECT (drop-down) lists have that wonderful selectedIndex feature, but, sadly, radio buttons do not have an equivalent.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Could you explain this like to me?

for(var i=0; i<document.MainForm.Answer.length; i++)

I am assuming the name of the form on the page this is being done is called "MainForm" and the radio buttons on that form are named "Answer". As I mentioned, radio buttons of the same name make up an array, so they have a "length" property which indicates how many elements are in the array. To cycle through that array, then, you must start at the 0-index (arrays are 0-based) and go up to the highest index, which is equal to length-1 (which is why it's "i<document..." and not "i<[red]=[/red]document..."). The i++ just increments i by one. The general construct of a for-loop is:

for(initialization; conditional; increment){instructions}

Steps:
(1) initialization

(2) evaluation of conditional.

(2a1)If conditional is true, follow instructions
(2a2)do whatever is in the increment part of the command (it doesn't actually have to be a form of incrementation)
(2a3)repeat (2), above

(2b) If conditional is false, skip the loop and move on.

I'm sure you already knew a lot of this, but wasn't quite sure how much you were asking for.

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
Actually that clears it up very well. I was just hoping I wouldn't end up having to evaluate every Radio group since I have 28 of them.

Thanks,
Aaron
 
Well, if you name them cleverly, you can do it dynamically. If, for example, they are: radioGroup0, radioGroup1, etc.

Code:
for(var x=0; x<28; x++)
{
 var radioGroup = document.forms["MainForm"].[b]elements["radioGroup"+x][/b];
 for(var i=0; i<radioGroup.length; i++)
 {
  if(document.MainForm.Answer[i].checked)
  {
   parent.document.forms["Form1"].[b]elements["someElement"+x][/b].value = radioGroup[i].value;
   break;  [i]//if this breaks out of BOTH for-loops, then drop it.[/i]
  }
 }
}

Can you follow what I did here?

Dave

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...east is east and west is west and if you take cranberries and stew them like applesauce
they taste much more like prunes than rhubarb does
[infinity]
 
I follow... I already have them all named so i think Ill just create one and copy paste / change names.

thanks
Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top