View Full Version : getting the checked radio button value from a parent window to a popup window.
Srikanth.S
09-14-2005, 02:14 PM
Hi,
How to get the checked radio button value of a parent window to a child window,the names of the radio buttons are similar.I tried using,
//in parent window
<input type="radio" name="parentradio" value="1">
<input type="radio" name="parentradio" value="2">
<input type="radio" name="parentradio" value="3">
//in child window
var selecteValue = window.opener.document.formname.parentradio.valuebut i'm getting the error as undefined value.Any suggestions regarding this to get the checked values.
Thanks in Advance,
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>parent child Windows popUp</title>
<script language="javascript">
var logElem;
var puWindow = null;
function bodyLoadFc() {
logElem = document.getElementById('logArea');
logElem.value = '';
writeLog('onload - start');
//
document.getElementsByName('parentradio')[1].checked = true;
writeLog('default selection: S 2');
//
launchPuWindow();
writeLog('PopUp Window creation - done');
//
var selIdx = getSelectedRadioButtonIndex();
puWindow.document.getElementById('selRadio').value = selIdx;
writeLog('Selected Radio Button Index: ' + selIdx);
//
writeLog('onload - end');
writeLog('>>> Select another radio button and verify value in PopUp Window');
}
function launchPuWindow() {
if(puWindow == null) {
var options = '';
options += 'height=100,';
options += 'width=300,';
options += 'location=0,';
options += 'menubar=0,';
options += 'resizable=0,';
options += 'scrollbars=0,';
options += 'directories=0,';
options += 'statusbar=0,';
options += 'toolbar=0';
puWindow = window.open("","", options);
}
var httpBody = '';
httpBody += '<html>';
httpBody += '<body style="background-color:#ffe0cc">';
httpBody += 'Selected Radio Button Index:<br>';
httpBody += '<input id="selRadio" type="text" readonly>';
httpBody += '</body>';
httpBody += '</html>';
puWindow.document.write(httpBody);
puWindow.document.close();
}
function getSelectedRadioButtonIndex() {
var ret = -1;
var pR = document.getElementsByName('parentradio');
for(var i=0; i<pR.length; i++) {
if(document.getElementsByName('parentradio')[i].checked == true) {
ret = i;
break;
}
}
return ret;
}
function rbOnClick() {
var selIdx = getSelectedRadioButtonIndex();
puWindow.document.getElementById('selRadio').value = selIdx;
writeLog('rbOnClick: Selected Radio Button Index: ' + selIdx);
}
function writeLog(msg) {
logElem.value += (new Date()).toString().substring(4,24) + ': ' + msg + '\n';
}
</script>
</head>
<body style="background-color:#ffe0cc" onload="bodyLoadFc();">
<table border="0" cellpadding="0" cellspacing="0">
<tr valign="top">
<td>
<fieldset style="width: 150px; text-align:right; font-family: Arial, Sans-Serif;">
<legend style="border-style:solid; border-width: 1px; font-size:14px;"> Radio Selection </legend>
<label style="font-size:13px">Select_1</label>
<input type="radio" name="parentradio" value="1" onclick="rbOnClick();"><br>
<label style="font-size:13px">S 2</label>
<input type="radio" name="parentradio" value="2" onclick="rbOnClick();"><br>
<label style="font-size:13px">Select 3</label>
<input type="radio" name="parentradio" value="3" onclick="rbOnClick();"><br>
</fieldset>
</td>
<td>
<fieldset style="width: 150px; text-align:right; font-family: Arial, Sans-Serif;">
<legend style="border-style:solid; border-width: 1px; font-size:14px;"> Log Info </legend>
<textarea id="logArea" rows="10" cols="80"></textarea>
</fieldset>
</td>
</tr>
</table>
</body>
</html>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.