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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass Form Values to ASP/SQL Page 1

Status
Not open for further replies.

sfalin

Technical User
Aug 14, 2001
72
US
I have an ASP form (PO) that supplies an automatic purchase order and within that form are several fields. I want to take the values of 2 of them (vCity & vState) and pass them to a pop-up window which allows searching by city and state for our vendors from a SQL table.

On form PO I have:
[ul]
Code:
<script language=&quot;JavaScript&quot;><!--
function newWindow(file,window) {
    msgWindow=open(file,window,'resizable=no,width=750,height=250');
    if (msgWindow.opener == null) msgWindow.opener = self;
}
//--></script>

<form>
<input type=&quot;button&quot; value=&quot;Locate Vendors&quot; onClick=&quot;newWindow('forms/dt_towers.asp','window2')&quot;>
</form>
[/ul]

And on page Dt_Towers.asp I have:
[ul]
Code:
<script language=&quot;JavaScript&quot;><!--
var strCity = opener.document.PO.vCity.value;
var strState = opener.document.PO.vState.value;
//--></script>
<%

Set rs=server.createobject(&quot;adodb.recordset&quot;)
sqlstmt=&quot;Select * from tblVendorList WHERE mail_st ='&quot;&strState&&quot;' and mail_city='&quot;&strCity&&quot;'; order by mail_City&quot;
set conn=server.createobject(&quot;adodb.connection&quot;)
conn.open=&quot;Provider=SQLOLEDB;Data Source=HGSNQ002;User Id=devpw;Password=pwdev&quot;
[/ul]
This is not working. I have NO experience with javascript, but I do know this is the best way to do what I need.

Can anybody help me???????

Scott
 
this won't work because your server-side asp is going to execute before the client-side javascript.

try this on PO
Code:
<script language=&quot;JavaScript&quot;><!--
function newWindow(file, window) {
	var strCity = document.PO.vCity.value;
	var strState = document.PO.vState.value;
	
	msgWindow=open(file + &quot;?city=&quot; + strCity + 
		&quot;&state=&quot; + strState, window, 
		'resizable=no,width=750,height=250');
	if (msgWindow.opener == null) msgWindow.opener = self;
}
//--></script>

<form>
<input type=&quot;button&quot; value=&quot;Locate Vendors&quot; onClick=&quot;newWindow('forms/dt_towers.asp','window2')&quot;>
</form>

and this on Dt_Towers.asp
Code:
<%
dim strCity, strState
strCity = request.queryString(&quot;city&quot;)
strState = request.queryString(&quot;state&quot;)

Set rs=server.createobject(&quot;adodb.recordset&quot;)
sqlstmt=&quot;Select * from tblVendorList WHERE mail_st ='&quot; & strState & &quot;' and mail_city='&quot; & strCity & &quot;'; order by mail_City&quot;
set conn=server.createobject(&quot;adodb.connection&quot;)
conn.open=&quot;Provider=SQLOLEDB;Data Source=HGSNQ002;User Id=devpw;Password=pwdev&quot;
%>

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
I'm not at work until Friday, but will try it then. From the looks of it, it should work. And if it does, you da man with a star.
 
Thanks, Jeff. I got it to work. You are the man.

Now, how can I take the results in 'window2' and send them back to fields on the PO form (in a frame called 'main'? The results are dynamically displayed from the SQL table. If the user chooses any one of the Vendors, I want to send that specific VendorID and VendorName back to the PO form and populate the appropriate fields (ISCnum & ISCnam)? This should be possible, but I have no idea how to do that.
 
if the fields in window2 are named VendorID and VendorName, then you should be able to like so:
Code:
<script type=&quot;text/javascript&quot;>
function sendItBack(f) {
  opener.parent.top.main.document.PO.ISCnum = f.VendorID.value;
  opener.parent.top.main.document.PO.ISCnam = f.VendorName.value;
  window.close();
}
</script>

<form>
  <input name=&quot;VendorID&quot;/>
  <input name=&quot;VendorName&quot;/>
  <input type=&quot;button&quot; value=&quot;done&quot; onclick=&quot;sendItBack(this.form);&quot;/>
</form>

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
I'll give it a shot on Monday. I'm wary on this one because each row in a table represents a different vendor and possibly being 30 or more to choose from in a city/state combination. The code I use just loops through the data and prints the text - no form fields. Each row, does, however, have a unique ID... maybe that'll help. I dunno. Won't know until I try. I'll keep ya posted.

I really do appreciate your help. You've been great.
 
if there are no form fields, we'll have to use a different approach. how does the user &quot;select&quot; the row?


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
There is currently no way to select it as this is a new process.

I could add a link to open the row's data in the same pop-up window as a single result (link would be 'dt_towers2.asp?ID=1234'), which could 'hidden' form fields and JavaScript to automatically send the data to the parent window and close 'window2'. Would that work?

Here is the page 'dt_towers2.asp' I just mocked up:
Code:
<%
ID = request.querystring(&quot;ID&quot;)

Set rs=server.createobject(&quot;adodb.recordset&quot;)
sqlstmt=&quot;Select * from tblVendorList WHERE ID=&quot;&ID
set conn=server.createobject(&quot;adodb.connection&quot;)
conn.open=&quot;Provider=SQLOLEDB;Data Source=HGSNQ002;User Id=devpw;Password=pwdev&quot;

rs.open sqlstmt, conn
If rs.eof then
response.write&quot;There are no records matching your search.  Please click <a href='vensearch1.asp'>here</a> to try a different search&quot;
else

%>
<html>
<HEAD>
	<TITLE>Downtime Towers List</TITLE>
	<STYLE>
		TD {font-family:arial; font-size:11pt}
		H1 {font-family:arial; font-size:16pt; color:navy}
		A {{font-family:arial; font-size:11pt}
	</STYLE>
</HEAD>
<body>
<h1>Downtime Towers List</h1>
<a href='vensearch1.asp'>Click Here to Search for Other Listings</A>
<hr color=&quot;Crimson&quot;>
<table border=1 CELLPADDING=2 CELLSPACING=0 ALIGN=center>
<%
ID=rs(&quot;ID&quot;)
mail_st=Trim(rs(&quot;Mail_st&quot;))
mail_city=Trim(rs(&quot;mail_city&quot;))
vndr_id=Trim(rs(&quot;vndr_ID&quot;))
code_value_desc=Trim(rs(&quot;code_value_desc&quot;))
vndr_nm=Trim(rs(&quot;vndr_nm&quot;))
daytime_phone_nbr=Trim(rs(&quot;daytime_phone_nbr&quot;))
nighttime_phone_nbr=Trim(rs(&quot;nighttime_phone_nbr&quot;))
Vndr_group=Trim(rs(&quot;Vndr_group&quot;))
%>
<TR>
<td>State:</TD><TD><INPUT NAME=state VALUE=&quot;<%=mail_st%>&quot;></td>
</TR><TR>
<td>City:</TD><TD><INPUT NAME=city VALUE=&quot;<%=mail_city%>&quot;></td>
</TR><TR>
<td>Vendor ID:</TD><TD><INPUT NAME=vndrid VALUE=&quot;<%=vndr_id%>&quot;></td>
</TR><TR>
<td>Vendor Type:</TD><TD><INPUT NAME=vndrtyp VALUE=&quot;<%=Code_value_desc%>&quot;></td>
</TR><TR>
<td>Vendor Name:</TD><TD><INPUT NAME=vndrnm VALUE=&quot;<%=vndr_nm%>&quot;></td>
</TR><TR>
<td>Daytime Phone:</TD><TD><INPUT NAME=dphn VALUE=&quot;<%=daytime_phone_nbr%>&quot;></td>
</TR><TR>
<td>Nighttime Phone:</TD><TD><INPUT NAME=nphn VALUE=&quot;<%=nighttime_phone_nbr%>&quot;></td>
</TR><TR>
<td>Vendor Rank:</TD><TD><INPUT NAME=vndrrnk VALUE=&quot;<%=vndr_group%>&quot;></td>
</tr></table>
<%end if%>
</body>
</html>
 
I've been working on this and am receiving an error. What I have is on 'dt_towers.asp' a link
Code:
<A HREF=&quot;dt_towers2.asp?ID=<%=ID%>&quot; TARGET=&quot;window2&quot;>Add to PO</A>
that is opening the selected item in the same popup window I opened from form PO on a new page 'dt_towers2.asp'. I ask the user to verify the data, then click the Submit button that runs your code:
[ul]
Code:
<script type=&quot;text/javascript&quot;>
function sendItBack(f) {
  opener.parent.top.main.document.PO.ISCnum = f.vndrid.value;
  opener.parent.top.main.document.PO.ISCnam = f.vndrnm.value;
  window.close();
}
</script>
[/ul]
The error I receive on clicking Submit is:
[ul]
Code:
Line: 23
Error: 'opener.parent.top.main.document.PO' is null or not an object
[/ul]
Here is dt_towers2.asp:
Code:
<%
ID = request.querystring(&quot;ID&quot;)

Set rs=server.createobject(&quot;adodb.recordset&quot;)
sqlstmt=&quot;Select * from tblVendorList WHERE ID=&quot;&ID
set conn=server.createobject(&quot;adodb.connection&quot;)
conn.open=&quot;Provider=SQLOLEDB;Data Source=HGSNQ002;User Id=devpw;Password=pwdev&quot;

rs.open sqlstmt, conn
If rs.eof then
response.write&quot;There are no records matching your search.  Please click <a href='vensearch1.asp'>here</a> to try a different search&quot;
else

%>
<html>
<HEAD>
	<TITLE>Downtime Towers List</TITLE>
	<STYLE>
		TD {font-family:arial; font-size:11pt}
		H1 {font-family:arial; font-size:16pt; color:navy}
		A {{font-family:arial; font-size:11pt}
	</STYLE>

<script type=&quot;text/javascript&quot;>
function sendItBack(f) {
  opener.parent.top.main.document.PO.ISCnum = f.vndrid.value;
  opener.parent.top.main.document.PO.ISCnam = f.vndrnm.value;
  window.close();
}
</script>
</HEAD>
<body> 


<h1>Downtime Towers List</h1>
<a href='vensearch1.asp'>Click Here to Search for Other Listings</A>
<hr color=&quot;Crimson&quot;>
<B>Please verify this is the ISC you wish to use.</B>
<FORM>
<table border=1 CELLPADDING=2 CELLSPACING=0 ALIGN=center>
<%
ID=rs(&quot;ID&quot;)
mail_st=Trim(rs(&quot;Mail_st&quot;))
mail_city=Trim(rs(&quot;mail_city&quot;))
vndr_id=Trim(rs(&quot;vndr_ID&quot;))
code_value_desc=Trim(rs(&quot;code_value_desc&quot;))
vndr_nm=Trim(rs(&quot;vndr_nm&quot;))
daytime_phone_nbr=Trim(rs(&quot;daytime_phone_nbr&quot;))
nighttime_phone_nbr=Trim(rs(&quot;nighttime_phone_nbr&quot;))
Vndr_group=Trim(rs(&quot;Vndr_group&quot;))
%>
<TR>
<td>State:</TD><TD><INPUT NAME=state VALUE=&quot;<%=mail_st%>&quot;></td>
</TR><TR>
<td>City:</TD><TD><INPUT NAME=city VALUE=&quot;<%=mail_city%>&quot;></td>
</TR><TR>
<td>Vendor ID:</TD><TD><INPUT NAME=vndrid VALUE=&quot;<%=vndr_id%>&quot;></td>
</TR><TR>
<td>Vendor Type:</TD><TD><INPUT NAME=vndrtyp VALUE=&quot;<%=Code_value_desc%>&quot;></td>
</TR><TR>
<td>Vendor Name:</TD><TD><INPUT NAME=vndrnm VALUE=&quot;<%=vndr_nm%>&quot;></td>
</TR><TR>
<td>Daytime Phone:</TD><TD><INPUT NAME=dphn VALUE=&quot;<%=daytime_phone_nbr%>&quot;></td>
</TR><TR>
<td>Nighttime Phone:</TD><TD><INPUT NAME=nphn VALUE=&quot;<%=nighttime_phone_nbr%>&quot;></td>
</TR><TR>
<td>Vendor Rank:</TD><TD><INPUT NAME=vndrrnk VALUE=&quot;<%=vndr_group%>&quot;></td>
</tr></table>
<INPUT TYPE=button VALUE=&quot;Use For PO&quot; onclick=&quot;sendItBack(this.form);&quot;>
</FORM>
<%end if%>
</body>
</html>
 
&quot;Error: 'opener.parent.top.main.document.PO' is null or not an object&quot;

this suggests that the opener has no form named &quot;PO&quot; in the frame named &quot;main&quot;

is this true?



=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
Ok, I figured out what was causing the error - that pesky Javascript case-sensitive business. But now, the fields on the 'po' form are not updating with any information. Does it have to be refreshed or something?
 
I've been playing with the reload function and can successfully get the parent window to reload, but any data that was entered into fields is lost.

From what I've read, the form has to go through a submission and refresh to capture the changes I needed. The problem here is the form is not completed when I open the popup window to search for Vendors and can't be submitted at this point due to field verification script.

Is there going to be a way for me to take the current incomplete form, search for vendors, push a user-selected vendor back to the parent from the popup, and then allow the user to complete the parent form?
 
>> &quot;I've been playing with the reload function and can successfully get the parent window to reload, but any data that was entered into fields is lost&quot;
this is correct behavior.

>> &quot;Is there going to be a way for me to take the current incomplete form, search for vendors, push a user-selected vendor back to the parent from the popup, and then allow the user to complete the parent form?&quot;
i'm not sure i understand your application flow - don't you have a parent form where the user can open a child window containing vendors, then select one of those which will be populated on the parent form? why would you need to refresh the window?


=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); }
 
What I need to happen is this:

1. PO form, in frame 'main', is opened and has about 50 required fields
2. 3/4 of the PO form is completed up to the point where the user can search for vendors
3. Upon clicking the locate vendors button, a pop-up window (window2) appears displaying results based on certain fields already filled on form PO. The vendors are then contacted to see if they can perform teh service needed
4. The vendor performing the service is selected from the listing and that vendor's detail is opened in window2.
5. A button on the vendor detail runs the function to pass certain information back to form PO in frame main
6. The information from the vendor detail populates the appropriate fields, but keeps all other information already entered
7. The user then completes the PO form and submits it, thus generating a PO number which is given to the vendor

Ok now, after typing this out, some light has been shed on the whole process. I'm going to have to do some re-thinking on this, and will probably have to go through all the politics of getting the process changed. My instinct is telling me to have the PO form submitted, excluding the vendor info, and have it submit to a new form to capture the vendor info (which will include the button for locate vendors. Once the vendor is chosen, the PO is then generated and can be given to the vendor.

Thank you so much for all your help adn I hope once I get the ball rolling on my new idea, you will be there to help me again.

Scott
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top