|
 |
asp_databases thread: Sending data from a page to a form field
Message #1 by "Moon Rahman" <moon.rahman@i...> on Thu, 23 Aug 2001 22:03:57
|
|
Hi,
I have a entry form where user enter customer name. Since the customer
table is too big I am letting them search and select. I am using a pop up
window to search. Everything works accept it doesn't retun the customer
name what I like to see in the customer name field.
Here is my entry form code:
<% if session("id") = "" then response.write("error") %>
<!-- #include file="adovbs.inc" -->
<HTML>
<HEAD>
<TITLE>new Request_2</TITLE>
<LINK REL="stylesheet" TYPE="text/css" HREF="nimstyle.css">
</HEAD>
<SCRIPT LANGUAGE="VBScript">
<!--
'This clientside VBScript validates the add form to make sure the user
'entered valid product information.
DIM ValidProduct
Sub ValidateAddForm
SET Add = document.AddForm
ValidProduct = True
Call CheckField (Add.metrixID.Value, "Please enter a product
name!")
Call CheckField (Add.SowHrs.Value, "Please enter a quantity per
unit!")
IF ValidProduct THEN
'MsgBox "I'm adding your project now!"
Add.Submit
END IF
'30
END Sub
Sub CheckField (ByVal strFieldValue, ByVal strMsg)
IF ValidProduct THEN 'Check to see if the field is invalid
'If a field name was not entered, prompt the user.
IF strFieldValue = "" THEN
ValidProduct = False
MsgBox strMsg
END IF
END IF
END Sub 'Check Field
-->
</SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var objWindow;
function Loading(){
objWindow=window.open("searchCustomer.asp");
}
</SCRIPT>
<BODY>
<%
' cID= Request.QueryString("CustomerID")
'Start processing form data if any
if Request.Form("metrixId") <> "" then
Set Conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionTimeout = Session("ConnectionTimeout")
conn.CommandTimeout = Session("CommandTimeout")
'Conn.CursorLocation = adUseClient
Conn.Open Session("ConnectionString")
originator = session("id")
'Create a recordset
Set ProductInfo = Server.CreateObject("ADODB.Recordset")
Set rs = Server.CreateObject("ADODB.Recordset")
'Create a query string
querystr = "SELECT * FROM request ORDER BY ID"
SqlStr= "Select * from customer order by ID"
'Set all the properties for the recordset
'ProductInfo.ActiveConnection = cn
ProductInfo.CursorType = adOpenKeyset
ProductInfo.LockType = adLockOptimistic
ProductInfo.Source = querystr
rs.Source= SqlStr
ProductInfo.Open, conn
rs.Open, Conn
'Call the Recordset method AddNew to create a new record in the
recordset
ProductInfo.AddNew
'Set the values of the new record equal to the values entered by
the user
'in the Add Product form.
ProductInfo("metrixID") = Request.Form("MetrixId")
ProductInfo("SowHrs") = Request.Form("Sowhrs")
ProductInfo("Originator") = session("id")
ProductInfo("RequestDate") = now ()
rs("id") = request.querystring ("id")
'Call the Recordset method Update to actually add the new record
to the
'SQL Server database
ProductInfo.Update %>
<!-- Output the new product entry to the user so they can see what
was added. -->
<H3>The following product information has been added to the
inventory database:</H3>
<HR>
<TABLE CELLPADDING=5>
<TR>
<% 'Output the row containing the added product's information
response.write ProductInfo("metrixID")
Response.write ProductInfo("SOWHrs")
%>
<BR>
<HR>
Return to the <A HREF="default.htm">Main Menu</A>
<% 'Close the recordset after use
ProductInfo.Close
else 'Output a form so that the user can add a new cd to the collection %>
<CENTER>
<H2>Add a New request</H2>
</CENTER>
<HR>
New Request Page
<FORM NAME="AddForm" ACTION="NewRequest.asp" METHOD=POST>
<input type=hidden name=ID value="0">
<input type=hidden name=status value="NEW">
<TABLE ALIGN=CENTER CLASS=formtable CELLPADDING=2>
<TR>
<TD>Metrix ID</TD>
<TD><INPUT TYPE="text" NAME="metrixID" MAXLENGTH=5></TD>
</TR>
<TR>
<TD>SOW Hours</TD>
<TD><INPUT TYPE="MEMO" NAME="SOWhrs" MAXLENGTH=200></TD>
</TR>
<TR>
<TD>Customer</TD>
<TD><input type="text" name="Name" size="25" value="<%rs
("ID")%>" readonly>
<img value=search onclick="JavaScript:Loading()"
border="0" src="[IMAGEDIR]/bttnSrch.gif"
alt="Search For Customer..." width="36" height="26"
></TD>
</TR>
<TR>
<TD></TD>
<TD><INPUT TYPE="button" NAME="AddButton"
VALUE="Add Product To Inventory"
onClick="VBScript:ValidateAddForm"></TD>
</TR>
</TABLE>
</FORM>
<BR><BR><HR>
Return to the <A HREF="default.htm">Main Menu</A>
<% End If %>
</BODY>
</HTML>
But when I pass the value from the other page I get a run time error.
please help me on this.
Thanks a lot,
Moon
Message #2 by gbrown@c... on Fri, 24 Aug 2001 12:32:24
|
|
Hi
I've not particularly read your code but the way I would do this is:-
Have the calling main form launch the popup via Javascript.
Have the popup present a screen which asks for whatever details you want
then post back to itself.
The popup then has a check which looks at the request and then does
body onload="opener.document.form1.customerselect.value='<%=request
("cust")%>';self.close()"
HTH
Regards
Graham
> Hi,
> I have a entry form where user enter customer name. Since the customer
> table is too big I am letting them search and select. I am using a pop
up
> window to search. Everything works accept it doesn't retun the customer
> name what I like to see in the customer name field.
>
> Here is my entry form code:
> <% if session("id") = "" then response.write("error") %>
> <!-- #include file="adovbs.inc" -->
>
> <HTML>
> <HEAD>
> <TITLE>new Request_2</TITLE>
> <LINK REL="stylesheet" TYPE="text/css" HREF="nimstyle.css">
> </HEAD>
>
> <SCRIPT LANGUAGE="VBScript">
> <!--
> 'This clientside VBScript validates the add form to make sure the user
> 'entered valid product information.
> DIM ValidProduct
>
> Sub ValidateAddForm
>
> SET Add = document.AddForm
> ValidProduct = True
>
> Call CheckField (Add.metrixID.Value, "Please enter a product
> name!")
> Call CheckField (Add.SowHrs.Value, "Please enter a quantity per
> unit!")
>
>
> IF ValidProduct THEN
> 'MsgBox "I'm adding your project now!"
> Add.Submit
> END IF
> '30
> END Sub
>
> Sub CheckField (ByVal strFieldValue, ByVal strMsg)
> IF ValidProduct THEN 'Check to see if the field is invalid
> 'If a field name was not entered, prompt the user.
> IF strFieldValue = "" THEN
> ValidProduct = False
> MsgBox strMsg
> END IF
> END IF
> END Sub 'Check Field
>
> -->
> </SCRIPT>
> <SCRIPT LANGUAGE="JavaScript">
> var objWindow;
> function Loading(){
> objWindow=window.open("searchCustomer.asp");
>
> }
> </SCRIPT>
>
> <BODY>
>
> <%
> ' cID= Request.QueryString("CustomerID")
>
> 'Start processing form data if any
> if Request.Form("metrixId") <> "" then
>
> Set Conn = Server.CreateObject("ADODB.Connection")
> conn.ConnectionTimeout = Session("ConnectionTimeout")
> conn.CommandTimeout = Session("CommandTimeout")
> 'Conn.CursorLocation = adUseClient
> Conn.Open Session("ConnectionString")
>
> originator = session("id")
> 'Create a recordset
>
> Set ProductInfo = Server.CreateObject("ADODB.Recordset")
> Set rs = Server.CreateObject("ADODB.Recordset")
>
> 'Create a query string
>
> querystr = "SELECT * FROM request ORDER BY ID"
> SqlStr= "Select * from customer order by ID"
>
> 'Set all the properties for the recordset
> 'ProductInfo.ActiveConnection = cn
>
> ProductInfo.CursorType = adOpenKeyset
> ProductInfo.LockType = adLockOptimistic
>
> ProductInfo.Source = querystr
> rs.Source= SqlStr
>
> ProductInfo.Open, conn
> rs.Open, Conn
>
>
> 'Call the Recordset method AddNew to create a new record in the
> recordset
> ProductInfo.AddNew
>
> 'Set the values of the new record equal to the values entered by
> the user
> 'in the Add Product form.
> ProductInfo("metrixID") = Request.Form("MetrixId")
> ProductInfo("SowHrs") = Request.Form("Sowhrs")
> ProductInfo("Originator") = session("id")
> ProductInfo("RequestDate") = now ()
>
>
> rs("id") = request.querystring ("id")
>
> 'Call the Recordset method Update to actually add the new record
> to the
> 'SQL Server database
> ProductInfo.Update %>
>
> <!-- Output the new product entry to the user so they can see what
> was added. -->
> <H3>The following product information has been added to the
> inventory database:</H3>
> <HR>
>
> <TABLE CELLPADDING=5>
> <TR>
>
> <% 'Output the row containing the added product's information
>
> response.write ProductInfo("metrixID")
> Response.write ProductInfo("SOWHrs")
> %>
> <BR>
> <HR>
> Return to the <A HREF="default.htm">Main Menu</A>
>
> <% 'Close the recordset after use
> ProductInfo.Close
>
> else 'Output a form so that the user can add a new cd to the collection
%>
>
> <CENTER>
> <H2>Add a New request</H2>
> </CENTER>
> <HR>
> New Request Page
>
> <FORM NAME="AddForm" ACTION="NewRequest.asp" METHOD=POST>
> <input type=hidden name=ID value="0">
> <input type=hidden name=status value="NEW">
> <TABLE ALIGN=CENTER CLASS=formtable CELLPADDING=2>
> <TR>
> <TD>Metrix ID</TD>
> <TD><INPUT TYPE="text" NAME="metrixID" MAXLENGTH=5></TD>
> </TR>
> <TR>
> <TD>SOW Hours</TD>
> <TD><INPUT TYPE="MEMO" NAME="SOWhrs" MAXLENGTH=200></TD>
> </TR>
> <TR>
> <TD>Customer</TD>
> <TD><input type="text" name="Name" size="25" value="<%rs
> ("ID")%>" readonly>
> <img value=search onclick="JavaScript:Loading()"
> border="0" src="[IMAGEDIR]/bttnSrch.gif"
> alt="Search For Customer..." width="36" height="26"
> ></TD>
> </TR>
>
> <TR>
> <TD></TD>
> <TD><INPUT TYPE="button" NAME="AddButton"
> VALUE="Add Product To Inventory"
> onClick="VBScript:ValidateAddForm"></TD>
> </TR>
> </TABLE>
>
> </FORM>
>
> <BR><BR><HR>
> Return to the <A HREF="default.htm">Main Menu</A>
> <% End If %>
>
> </BODY>
> </HTML>
>
> But when I pass the value from the other page I get a run time error.
> please help me on this.
>
> Thanks a lot,
>
> Moon
|
|
 |