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

Frames and Forms

Status
Not open for further replies.

BLarche

Programmer
Nov 29, 2004
25
US
Chessbot,

You had helped me a few days ago regarding clicking a radio button in a popup window and having it select a dropdown item depending on which radio button was selected.

I got that working. However, in that window I am using a frameset. One frame has the radio button and the other has the submit button. How do I link these two together to make it work properly?

Thanks.
 
In response to my original post, I will paste the code that I am using as well as the website that I am trying to incorporate this into:

Website (On the right, click "Select Image"):



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.checked)
{
selectedValue = radios.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.value == selectedValue)
{
sel.selectedIndex = i;
window.close();
return;
}
}
alert('No option with value ' + selectedValue + ' found!');
}

// -->
</script>
 
Put setValue in the bottom frame, using
Code:
function setValue()
{
  var selectedValue = "";
  var radios = [red]parent.frames['imageframe'].[/red]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!');
}

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakesperean sonnet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top