By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,770 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

How to load drop down list vaules from the main page to popup window?

P: 1
Hi,
Functionality is like when pressing 'CTRL+click' on drop down list in the main jsp page, a popup window appears with a list box contains all the values of the drop down clicked on the main page. But some times when we expand the drop down and press "CTRL+click" on any of the options in the main jsp, values are not getting populated in the popup window List box. Is any other options to load values from main jsp to popup jsp fle?

Pls see the code used in the popup window to list the values:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2.     function populateList() {     
  3.      var size = eval("window.opener.document.forms[0]."+elementName+".length");
  4.      for(var i = 0;i<Number(size);i++){
  5.      var txt = eval("window.opener.document.forms[0]."+elementName+".options["+i+"].innerText");
  6.      var val = eval("window.opener.document.forms[0]."+elementName+".options["+i+"].value");
  7.      var newOption = new Option(txt, val, false, false);
  8.      document.forms[0].listBox.options[i] = newOption;
  9.      }
  10.     }
  11.  
  12.     </script>
  13.   <body onload = "javascript:populateList();">
Feb 13 '07 #1
Share this Question
Share on Google+
1 Reply


acoder
Expert Mod 15k+
P: 16,027
Don't use eval.
Try this instead:
Expand|Select|Wrap|Line Numbers
  1. <script>
  2.     function populateList() {
  3.      var size = window.opener.document.forms[0][elementName].length;
  4.      for(var i = 0;i<size;i++) {
  5.      var txt = window.opener.document.forms[0][elementName].options[i].text;
  6.      var val = window.opener.document.forms[0][elementName].options[i].value;
  7.      var newOption = new Option(txt, val, false, false);
  8.      document.forms[0].listBox.options[i] = newOption;
  9.      }
  10.     }
  11. </script>
  12. <body onload = "javascript:populateList();">
I'm assuming you've set the elementName somewhere. If not, that should be the problem.
Feb 13 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.