Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

open new window and pass parameters from a button

Status
Not open for further replies.

gojohnnygogogogo

Programmer
May 22, 2002
161
GB
hello, I am trying to open a new window from a click on a button, so far I have this, but the parameters are not passing.
any ideas ?
thanx

<script language=&quot;JAVASCRIPT&quot;>
function opencalc(){

var calculate = document.c1

window.open('viewcalc.asp', 'Calculation', 'width=650,height=250');
}
</script>

<TD BORDERCOLOR=#336699 nowrap><FONT SIZE=1 FACE=&quot;Arial&quot; COLOR=#000000>
<form method=&quot;post&quot; name=&quot;c1&quot; action=&quot;./viewcalc.asp&quot;>
<INPUT TYPE=hidden name=startdate value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;I_SD&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=commitdate value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;I_CD&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=PTID value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;Prov_ID&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=HrsPerWeek value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;HrsPerWeek&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=name value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;name&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=EBname value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;EBname&quot;).Value)%>&quot;>
<input type=button class=&quot;bttn2&quot; name=&quot;calc&quot; value=&quot;Calculate Amount&quot; onClick=&quot;return opencalc()&quot;>
</td></form>
 
what's the code in the new window? using post, you need to use
Code:
request.form(&quot;formname&quot;)
. is it posible that you are expecting get(
Code:
request.querystring(&quot;formname&quot;)
)?
 
The problem is due to the fact that you're not actually submitting your form. You need to do something like:

<form name=&quot;c1&quot; target=&quot;_new&quot; ...etc... ...etc...>

and in your button onClick=&quot;document.c1.submit()&quot;
(or use a button type submit)

However, this will open a window without the formatting you use above...

So I looked at your code and come up with the following:

<script language=&quot;JAVASCRIPT&quot;>
function opencalc(){

var calculate = document.c1


window.open('next.asp', 'Calculation', 'width=650,height=250');
document.c1.submit();
}
</script>

Then in your form tag:

target=&quot;Calculation&quot;

Hope that helps.
 
sorry, that didn't work, so I have :

<script language=&quot;JAVASCRIPT&quot;>
function opencalc(){

var calculate = document.c1

window.open('viewcalc.asp', 'Calculation', 'width=650,height=250')
document.c1.submit();
}
</script>


<TD BORDERCOLOR=#336699 nowrap><FONT SIZE=1 FACE=&quot;Arial&quot; COLOR=#000000>

<form method=&quot;post&quot; name=&quot;c1&quot; action=&quot;./viewcalc.asp&quot; target=&quot;calculate&quot;>
<INPUT TYPE=hidden name=startdate value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;I_SD&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=commitdate value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;I_CD&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=PTID value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;PTID&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=HrsPerWeek value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;HrsPerWeek&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=name value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;name&quot;).Value)%>&quot;>
<INPUT TYPE=hidden name=EBname value=&quot;<%=Server.HTMLEncode(rs.Fields(&quot;EBname&quot;).Value)%>&quot;>
<input type=button class=&quot;bttn2&quot; name=&quot;calc&quot; value=&quot;Amount&quot; onclick=&quot;return opencalc();&quot;>
</td>
</form>
 
Should be

target=&quot;Calculation&quot;

(the name given in window.open -- ('viewcalc.asp', 'Calculation', ...)

If you can't get it to work, let me know what error messages or results you are getting.
 
Hmm, not sure. Here's a sample that might help, it's pretty much what you have but without the recordset values (I still used asp variables though), and it works for me:

1st page:

<%@ language=&quot;vbscript&quot;%>

<%
Option Explicit

dim testVal_1, testVal_2, testVal_3, testVal_4, testVal_5

testVal_1 = &quot;testValue 1&quot;
testVal_2 = &quot;testValue 2&quot;
testVal_3 = &quot;testValue 3&quot;
testVal_4 = &quot;testValue 4&quot;
testVal_5 = &quot;testValue 5&quot;
%>

<html>
<head>
<title>Test</title>

<script language=&quot;JAVASCRIPT&quot;>
function opencalc(){

window.open('next.asp', 'Calculation', 'width=650,height=250');
document.c1.submit();

}
</script>

</head>
<body>

<TD BORDERCOLOR=#336699 nowrap><FONT SIZE=1 FACE=&quot;Arial&quot; COLOR=#000000>
<form method=&quot;post&quot; name=&quot;c1&quot; target=&quot;Calculation&quot; action=&quot;./next.asp&quot;>
<INPUT TYPE=hidden name=foo1 value=&quot;<%=testVal_1%>&quot;>
<INPUT TYPE=hidden name=foo2 value=&quot;<%=testVal_2%>&quot;>
<INPUT TYPE=hidden name=foo3 value=&quot;<%=testVal_3%>&quot;>
<INPUT TYPE=hidden name=foo4 value=&quot;<%=testVal_4%>&quot;>
<INPUT TYPE=hidden name=foo5 value=&quot;<%=testVal_5%>&quot;>
<input type=button class=&quot;bttn2&quot; name=&quot;calc&quot; value=&quot;Calculate Amount&quot; onClick=&quot;return opencalc()&quot;>
</td></form>

</body>
</html>


2nd Page (next.asp):

<%@ language=&quot;vbscript&quot;%>

<%
Option Explicit

response.write request.form(&quot;foo1&quot;) & &quot;<br>&quot;
response.write request.form(&quot;foo2&quot;) & &quot;<br>&quot;
response.write request.form(&quot;foo3&quot;) & &quot;<br>&quot;
response.write request.form(&quot;foo4&quot;) & &quot;<br>&quot;
response.write request.form(&quot;foo5&quot;) & &quot;<br>&quot;
response.write request.form(&quot;foo6&quot;) & &quot;<br>&quot;

%>
 
dodgy init ?!
I can't get this to work, is there a way I can do it on th other page ?

so onload event run a script which resizes and removes menubars/toolbars/scrollbars ?


<script>
window.resizeto(650,250)
?then don't know how to remove toolbars?
</script>

thanks for all your help

 
Why not just do this:
<script language=&quot;JAVASCRIPT&quot;>
function opencalc(){

window.open('next.asp?var1=<%=rs(var1)%>&var2=<%=rs(var2)%>&var3=<%=rs(var3)%>', 'Calculation', 'width=650,height=250');
document.c1.submit();

}
</script>
<body onload=&quot;opencalc()&quot;>

then on your new popup window ask for the querystrings instead of request.form.
 
nice, I am now using what megalene suggested but when the new window opens it only shows the last record, not the record I clicked on.

any suggestions ?

this is what I have so far within a table :

<script language=&quot;JAVASCRIPT&quot;>
function opencalc(){
window.open('viewcalc.asp?startdate=<%=Server.HTMLEncode(rs(&quot;I_SD&quot;))%>&commitdate=<%=Server.HTMLEncode(rs(&quot;I_CD&quot;))%>&PTID=<%=Server.HTMLEncode(rs(&quot;Prov_ID&quot;))%>&HrsPerWeek=<%=Server.HTMLEncode(rs(&quot;HrsPerWeek&quot;))%>&name=<%=Server.HTMLEncode(rs(&quot;name&quot;))%>&EBname=<%=Server.HTMLEncode(rs(&quot;EBname&quot;))%>', 'Calculation', 'width=650,height=250');

}
</script>

<TD BORDERCOLOR=#336699 nowrap><FONT SIZE=1 FACE=&quot;Arial&quot; COLOR=#000000>
<input type=button class=&quot;bttn2&quot; name=&quot;calc&quot; value=&quot;Calculate Amount&quot; onClick=&quot;return opencalc()&quot;>
</td>

each row contains different info. when I click on the Calculate amount button I wantto pass the current info. to the next page.

 
Instead of using this opencalc function, why not embed everything in forms?
When you are generating your html, just make each row a seperate form.
<tr>
<td>
<form method=&quot;GET&quot; action=&quot;whatever&quot; target=&quot;titleofyournewwindow&quot;>

<!-- all your form stuff here -->
<!-- your button for this row here -->
</form>
</td>
</tr>

This way each row can open it's own window.

As for returning values (Which I believe you were trying to do, but weren't quite):
If you want the values back you can declare some extraneous var's in javascript tags and from your pop-up window do a window.parent.whatever to access them. I like doing something similar with hidden iframes because you can mix client and server-side interaction without ever going to a new page (works wonders for faking auto-completion from a db).

-Tarwn
You may get it, but I lost track of it a few sentences back :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top