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

Radio Button selects DropDown Menu in New Window

Status
Not open for further replies.

BLarche

Programmer
Nov 29, 2004
25
US
I have a window that is popped up when the user clicks "Select Image." Inside of that window contains 2 frames. One of the frames has radio buttons and the other frame has the submit button for those radio buttons. When the user selects which radio button and clicks submit, I want the value of the radio button to select a dropdown menu item from the original window. The radio buttons are generated from the same database as the dropdown menu items, and are linked by the "ItemNum" field. I already have some code that does what I ask above, but it will not work with multiple frames in the popup window. Can anyone give me some advice on what needs to be done? I can paste the code that I currently have.
 
From the frame in the pop window, you will need to refer to the parent opener like this...

parent.window.opener.nameOfForm.nameOfSelect.selectedIndex = someValue

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Below is the code that I am currently using:

Code:
<script type="text/javascript">
<!--

function setValue()
{
  var selectedValue = "";
  var radios = document.forms[0].elements['radios'];
  if (!radios)
  {
    alert("No radio buttons found!");
    return;
  }
  if (!radios.length)
    selectedValue = radios.value;
  else
  {
    for (var i=0; i<radios.length; i++)
    {
      if (radios[i].checked)
      {
        selectedValue = radios[i].value;
        break;
      }
    }
  }
  if (selectedValue == "")
  {
    alert('Please select a value!');
    return;
  }
  var sel = opener.document.forms['outputForm'].elements['productImage'];
  // change to your form's name and select's name
  if (!sel)
  {
    alert('Select box not found!');
    return;
  }
  var options = sel.options;
  if (!options.length)
  {
    sel.selectedIndex = 0;
    window.close();
    return;
  }
  for (var i=0; i<options.length; i++)
  {
    if (options[i].value == selectedValue)
    {
      sel.selectedIndex = i;
      window.close();
      return;
    }
  }
  alert('No option with value ' + selectedValue + ' found!');
}

// -->
</script>

And then the onclick for the submit button:
Code:
onclick="parent.frames['mainFrame'].document.forms['outputForm'].submit();"

But I cannot get these two to link together. What else do I need to add?
 
I haven't tested it, but something like this? (Change the italic text to match your object names)
Code:
<script>
function doit(){
  [green]// Get the selected radio button value[/green]
  var rdo=parent.[i]radioFrame[/i].document.getElementsByName("[i]radioGroupName[/i]"), selectedRadioValue='';
  for(i=0;i<rdo.length;i++){
    if(rdo[i].checked){
      selectedRadioValue=rdo[i].value;
      break;
    }
  }

  [green]// Set the drop-down[/green]
  var sel=parent.opener.document.[i]formName[/i].[i]selectName[/i];
  for(i=0;i<sel.options.length;i++){
    if(sel.options[i].value==selectedRadioValue){
      sel.options[i].selected=true;
      break
    };
  }
}
</script>
<input type="button" value="Submit" onclick="doit()">

Adam
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done." Andy Rooney.
 
In that last sample of code, where would I place each of those pieces of code? In the frame with the radio buttons or the frame with the submit button?
 
With the submit button

Adam
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done." Andy Rooney.
 
Nevermind. I forgot to change the onclick properties. I also added window.close();, but where should I add it? The window is not closing.
 
You should be able to include window.close() at the end of the function right before the last closing }

Adam
"Computers make it easier to do a lot of things, but most of the things they make it easier to do don't need to be done." Andy Rooney.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top