Pass Value from Checkbox in Child Window to the Parent Window

This will populate you textarea based on the selected item on child window.
I hope the image above can be the explanation. :P
Anyway here's the code:
1 .index.html

<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>TITLE</title>

</head>
<body>

<a ating="" href="javascript:void(0);" list.html="" onclick="window.open(" width="550,height=200,left=150,top=200,toolbar=1,status=1,">Choose keywords</a>:

<form name="frm">
<textarea id="getval1" name="getval1" placeholder="choose keywords"></textarea>

<textarea id="getval" name="getval" placeholder="choose keywords"></textarea>

<textarea id="getval2" name="getval2" placeholder="choose keywords"></textarea>

</form>
</body>
</html>

2. list.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Choose Keywords</title>
</head>

<body>
KeyWords:<br />
 <div id="getval">
   <input type="checkbox" value="Recite" />
    Recite<br />
    <input type="checkbox" value="Sang" />
    Sang<br />
    <input type="checkbox"  value="Describe" />
    Describe<br />
    <input type="checkbox" value="Discuss" />
    Discuss<br />


    <input type="button" name="button" id="button" value="Insert" onclick="insertVals('getval');" />
</div>
<br />

<script type="text/javascript">
 function insertVals(namesContainerID)
 {
  var inputs = document.getElementById(namesContainerID).getElementsByTagName('input');
  var insertStr = '';
  for (var i=0; i<inputs.length; i++)
  {
   if (inputs[i].type == "checkbox")
   {
    if (inputs[i].checked)
    {
     insertStr += (insertStr != '') ? '\n' : '';
     insertStr += inputs[i].value;
    }
   }
  }
  if (window.opener.document.getElementById('getval1').value ==''){
  window.opener.document.getElementById('getval1').value = insertStr;
  window.close();
  }
  else if (window.opener.document.getElementById('getval').value == ''){
    window.opener.document.getElementById('getval').value = insertStr;
    window.close();
  }
   else if (window.opener.document.getElementById('getval2').value == ''){
    window.opener.document.getElementById('getval2').value = insertStr;
    window.close();
  }
 }
 
</script>

</body>
</html>

Better install XAMPP if it doesn't work in Chrome then create a folder on htdocs and put the two html files there, then access it through localhost.

Popular posts from this blog

Set table width to 100% on PDF export in Datatables

Hot/Cute flat-chested Girls