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

Selecting DropDown from Radio Button in Different Window

Status
Not open for further replies.

BLarche

Programmer
Nov 29, 2004
25
US
How do I select a dropdown value in a dropdown on the main page from a value submitted by a radio button in a popup page? These values are all generated by a database, so only the values on the dropdown will be the available values that can be selected by a radio button.

Thanks for your help!
 
What is the same between the radio buttons and the drop down? The same order? The same values? The same names?

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
The values will be the same. For instance, the value in the dropdown is "CAPLG" and the value for the radio button should also be "CAPLG".

Thanks.
 
Ok. Your popup should look like this:
Code:
<html>
<head>
<title>Choose</title>
<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['formname'].elements['selectname'];
  // 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>
</head>
<body>
<h3>Please select a radio button</h3>
<form>
 <input type="radio" name="radios" value="a">A<br>
 <input type="radio" name="radios" value="b">B<br>
 <!-- ... -->
 <input type="button" onclick="setValue();" value="Finish">
</form>
</body>
</html>

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Okay. What will my code on the main page look like? I want a link that says, "Select Image", and it opens the popup. Is it just a simple popup link? Or is there more to it?
 
Yes, it would just be a popup link ([tt]window.open()[/tt]).

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Awesome. Thanks for your quick reply and help. Seems that all is working well!!
 
Great!

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top