Selecting a dropdown list from a child window

Hello,

I have opened a new window from the parent window and this is used to search for extra information and when found, I close this window sending the results back to the parent window populating some text and textarea with the information.

Here is where i'm struggling:

On the parent window, I have a select/option list pre-populated with values.  The 'value' has an integer value 312,231,23,98 etc.. and these have text place names which are displayed in the list itself.   What I need to do is send for example 312 from the child window back to the parent window and to change the selection to the correct option sent from the child window.

Here is the code i'm using on the child window to populate the other options on the parent window.  The line which has 'window.opener.document.fault.frm_franchise.value' is the line of code in question.

function close_and_populate(){

window.opener.document.fault.frm_postcode.value = document.results.hid_postcode.value;
window.opener.document.fault.frm_node.value = document.results.hid_node_ref.value;
window.opener.document.fault.frm_dhcp.value = document.results.hid_dhcp_name.value;
window.opener.document.fault.frm_ubr.value = document.results.hid_ubr_dns.value;
window.opener.document.fault.frm_customers.value = document.results.hid_customers.value;
window.opener.document.fault.frm_franchise.value = document.results.hid_franchise_no.value;

window.close();
}

Many thanks,
Paul
trancetopiaAsked:
Who is Participating?
 
sajuksCommented:
window.opener.document.fault.frm_franchise.value = document.results.hid_franchise_no.value;
it should be value and not selected index for your case as you are passing the value.

aslo please not that in your option value you've  the value as "375 Aylesbury & Chiltern" while you are passing "375" that wont work.

eg:
<form method="post" action="add_fault.asp?type=full" name="fault" onsubmit="return checkWholeForm(); ">
<INPUT TYPE="text" NAME="myhidden">
     <select name="frm_franchise" id="frm_franchise" onchange = "window.open('2.html')">
          <option value="Unknown">Unknown</option>
          <option value="105">105 Andover</option>
          <option value="375">375 Aylesbury & Chiltern</option>
          <option value="240">240 Bearsden & Milngavie</option>
          <option value="317">317 Bexley</option>
          <option value="430">430 Bolton</option>
     </select>

</form>


in child
<SCRIPT LANGUAGE="JavaScript">
<!--
function close_and_populate(){
window.opener.document.fault.frm_franchise.value = document.results.hid_franchise_no.value;
window.close();
}
//-->
</SCRIPT>

<form method="post" action="#" name="results">
     <input type="hidden" name="hid_franchise_no" value="375">
     <input type="button" value="Post Details" onClick="javascript:close_and_populate();">
</form>
0
 
sajuksCommented:
set the selectedindex value in ur close_and_populate function  and see if that works


window.opener.document.getElementById(frm_franchise).selectedIndex = document.results.hid_franchise_no.value

0
 
trancetopiaAuthor Commented:
Hi Sajuks,

I've tried you suggestion and that didn't work.  Any other ideas?

Thanks,
Paul
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
trancetopiaAuthor Commented:
For some reason this isn't working for me.  I didn't have an ID in the parent select list which I though was causing the problem but i've put that there and it's still not working.

Here is an abstract of code from my parent window form to help:

<form method="post" action="add_fault.asp?type=full" name="fault" onsubmit="return checkWholeForm(); ">
      <select name="frm_franchise" id="frm_franchise">
            <option value="Unknown">Unknown</option>
            <option value="105 Andover">105 Andover</option>
            <option value="375 Aylesbury & Chiltern">375 Aylesbury & Chiltern</option>
            <option value="240 Bearsden & Milngavie">240 Bearsden & Milngavie</option>
            <option value="317 Bexley">317 Bexley</option>
            <option value="430 Bolton">430 Bolton</option>
      </select>
      <input type="submit" value="Submit fault" onsubmit="return check_frm_action(); " />
</form>

My child window code looks like this:

function close_and_populate(){

window.opener.document.fault.frm_postcode.value = document.results.hid_postcode.value;
window.opener.document.fault.frm_node.value = document.results.hid_node_ref.value;
window.opener.document.fault.frm_dhcp.value = document.results.hid_dhcp_name.value;
window.opener.document.fault.frm_ubr.value = document.results.hid_ubr_dns.value;
window.opener.document.fault.frm_customers.value = document.results.hid_customers.value;
window.opener.document.getElementById('frm_franchise').selectedIndex = document.results.hid_franchise_no.value;

window.close();
}

<form method="post" action="#" name="results">
      <input type="hidden" name="hid_franchise_no" value="375">
      <input type="button" value="Post Details" onClick="javascript:close_and_populate();">
</form>



Thanks,
Paul
0
 
trancetopiaAuthor Commented:
Increased point value
0
 
trancetopiaAuthor Commented:
Hi, I looked at your reply and I added the full name instead of the value: 375 Aylesbury & Chiltern and it's now working.

Not sure what you were trying to do with the additional onchange = "window.open('2.html') but points awarded, thanks for your help.
0
 
sajuksCommented:
"the additional onchange = "window.open('2.html') "
that was my code testing...i gave the script for two pages, 1.html and 2.html so that u could run it and check.

Thanks for the points and grade
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.