Link to home
Start Free TrialLog in
Avatar of abenbow
abenbow

asked on

open a new window with a form in it, make a selection in the form and submit, format the variable then pass it back to the original wndow

Hi all, real bobby dazzler here.

I have a complicated form which creates a sql query. Everything works but the client has requested a change.

At the moment there is a list of postcodes areas as tick boxes. This allows the user to tick the postcode areas that they want to search and when the form is submitted all the ticked tick boxes are gathered together and an array is created. This works perfectly.

The change is that instead of 125 tick boxes (all created dynamically) the client now wants a text box so that the user just types in the required postcodes eg AB,ST,E.... and so on BUT if they don't know the postcodes then we have a link to a popup box containing the 125 dynamically created tickboxes. The user then ticks the required postcodes and clicks submit. The ticked tick boxes are then gathered together, formatted and sent back to the original form and put into the textbox, closing the popup on the way.

So basically I have all the code but the problem is that when I try to combine the javascript open window, get info, pass info back to opener, close window (I can do this easily, and have it working) with my 125 tickboxes then it doesn't work

some code

OK THIS OPENS THE POPUP WINDOW
[CODE]
<script language="JavaScript">
function restart(){
document.eroll_form.post2.value = post2;
mywindow.close();
}
</script>
<form action="" method="post" name="eroll_form" id="eroll_form">
  <input type="text" name="post2" value="">
POST 2 <a href="javascript:showPost2()">Show Post 2</a>
</form>
[/CODE]

THIS IS THE POPUP WINDOW - I'm not using dynamic tickboxes at this point, just a sample of 3 for speed.
[code]
<script language="JavaScript">
function generateArray(){
<%
post_code = ""
post_code = Split(Request.form("postcode2"),",")
For intX = 0 to UBound(post_code)
    post_code(intx) ="'"&trim(post_code(intx))&"'"
Next
postcode_array = Join(post_code,",")
%>
opener.post2 = postcode_array;
opener.restart();
self.close();
}
</script>



<html>
<head>
<title>post2</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="post_form">
<table width="90%" border="0" cellspacing="1" cellpadding="1">
  <tr>
    <td>AB</td>
    <td><input name="postcode2" type="checkbox" id="ab" value="ab"></td>
  </tr>
  <tr>
    <td>ST</td>
    <td><input name="postcode2" type="checkbox" id="ST" value="ST"></td>
  </tr>
  <tr>
    <td>E</td>
    <td><input name="postcode2" type="checkbox" id="E" value="E"></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><input type="button" value="Submit" onClick="javascript:generateArray();"></td>
    <td>&nbsp;</td>
  </tr>
</table>
</form>
</body>
</html>
[/code]


AND THIS IS THE FORMAT AND PASSBACK CODE THAT I AM HAVING THE PROBLEM WITH FROM THE ABOVE CODE
[code]
<script language="JavaScript">
function generateArray(){
<%
post_code = ""
post_code = Split(Request.form("postcode2"),",")
For intX = 0 to UBound(post_code)
    post_code(intx) ="'"&trim(post_code(intx))&"'"
Next
postcode_array = Join(post_code,",")
%>
opener.post2 = postcode_array;
opener.restart();
self.close();
}
</script>
[/code]

now the bit betwen the <% %> is as it was from the asp page that I was using originally because that works(i know that things like the <% %> need to come out), I have butchered it so much that I thought it best to revert to what works. The problem is converting that into a working javascript

thanks in advance

Andy
Avatar of abenbow
abenbow

ASKER

sorry, I just wanted to clarify. If I just set opener.post2 = postcode_array; to opener.post2 = 'st'; and remove all the code between <% %> then it works, passing st back into the text box.


Andy
Hi Andy,

so do you still need help or you've fixed the problem

Regards

Peter
Avatar of abenbow

ASKER

still need help :(
OK,
since now I'm in hurry, I'll tel you some principles how it should work. Tomorrow I'll make some simple examples and post it.

1. On the parent form (window), you need to add a hidden field like <INPUT TYPE="hidden" name="hdval" ...
2. On child form (window), on click or onSelect or onSubmit event (what ever you use to set selected post code), you need to set the value of hidden field on the PARENT form to the selected value as :

//set value of hidden field on parent form
window.parent.opener.document.parFormName.hdval.value = selected_value;
//then set FOCUS to the some visible object on parent form -> !!!
window.parent.opener.document.parFormName.someButton.focus(); //-> !!!
//Finally close child form
window.close();

3. Define onFocus event to the someButton visible element on parent form to activate function that will just do : document.formName.submit();
Of course, you will need to preserve this function to NOT SUBMIT form if value of hidden field is null or empty string

Basically this is the concept - but this is 100% sure it will work. I have seen many other solutions that sometimes works and sometimes does not (but this is "beaty" of JavaScript)

Regards

Peter
Avatar of abenbow

ASKER

okaay

what you are saying makes sense but the problem that i am having is getting the ticked boxes out, i haven't got a problem passing something to the opener, it the act of gathering the data from the form and formatting it that is the problem or its the act of converting my asp code into javascript

ie
 opener.post2 = 'st';  works

but i want to create an array of ticked boxes called  postcode_array and then use

opener.post2 =  postcode_array;

the problem is the array :)

this asp code will create the array

post_code = ""
post_code = Split(Request.form("postcode2"),",")
For intX = 0 to UBound(post_code)
    post_code(intx) ="'"&trim(post_code(intx))&"'"
Next
postcode_array = Join(post_code,",")


but not in the javascript, what i need is a way of doing what the asp does in javascript or a way of running the asp when i click submit then running the javascript to pass it to the opener and close the window

Andy
Hm,
it seems I did not understend what you need (sorry).

I think now I understand :
In popup window you will have 125 values, each of them associated with one check box. Then you select some of them and onSubmit, you need to pass back information about WHAT check boxes were checked.
ie, you need to pass values of selected items back to opener

Am I correct ?

PS. If I'm correct, then it should not be problem

One more question :

How do you make this list of of postcodes in the popup window :
1. does popup window have hardcoded table with postcodes and check boxes, or
2. you pass list of postcodes FROM parent window to the child window (as an array)

As I see from your code, you do option 2.

If you do option 2, I do not see some necessity of this, but I'm not going to comment your needs :)
SOLUTION
Avatar of ftaco96
ftaco96

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of abenbow

ASKER

hi guys

sorry just got chance to look at this properly

 pnedic

the postcodes are generated dynamically in the popup window - there are 125 at the moment, I'm buggered if I'm creating that many tick boxes :o

 ftaco96

Thx for that, I'll give that a go tonight, ta



Andy
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial