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

Pop-Up Window for Database Entry 2

Status
Not open for further replies.

Marmalade

Technical User
Jan 30, 2002
29
US
Hi everybody,

I've built an ASP form that uses database-driven list boxes. I wanted to give users the opportunity to add items to the table that provides the list box options, so I coded a JavaScript pop-up that refers to an ASP page for data entry.

Problem is, once you've added an item to the database via the pop-up, you have to refresh the main form page for the addition to be reflected on the list - and the act of refreshing wipes out any data previously entered on the form!

Does anyone know a way around this?

Thanks,

M
 
You could do this all in the same page. I created a few pages that have drop down lists that allows users the ability to look up information, edit it, delete it, or add a new item all on one page.

What does your page look like? Do you have a link available?
 
That sounds great; unfortunately, the page is in development on my workstation, so I can't send a link (but I could send a screenshot, if that would be helpful).

How were you able to do all of that on one page?

M
 
<%@ Language=VBScript %>
<%Option Explicit%>
<%Response.Buffer = True%>
<!-- #include FILE=config.inc -->
<%
'Dim Vars Here
Dim objConn, objConn2,test
Dim objRec
Dim strSQL, strBuff, strBuffTest, strDept, strEmp, strSQL2,x
Dim rowcolor
Dim txtFName, txtLName, txtEmail, txtPhoneExt, txtFax, txtID
Dim txtCellPhone, txtPager, txtOtherContact, intDepartment, intSupervisorFlag, intSupervisorID
if Request.Form(&quot;testbox&quot;) = &quot;OK&quot; and Request.Form(&quot;txtID&quot;) <> &quot;&quot; then
'Open Database
Set objConn2 = Server.CreateObject(&quot;ADODB.Connection&quot;)
'Set objRec2 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
objConn2.open strConn

'Create SQL statement
strSQL2 = &quot;DELETE FROM EmpInfo WHERE ID=&quot;
strSQL2 = strSQL2 & (Request.Form(&quot;txtID&quot;))

'Open Recordset
objConn2.execute(strSQL2)

Response.Write (&quot;<script>alert('&quot; & Request.Form(&quot;FName&quot;) & &quot; &quot; & Request.Form(&quot;LName&quot;) & &quot; has been deleted.')</script>&quot;)

'Clean up
objConn2.Close
Set objConn2 = nothing
else
if Request.Form (&quot;btnSubmit&quot;) <> &quot;&quot; then
'Open Database
Set objConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Set objRec = Server.CreateObject (&quot;ADODB.Recordset&quot;)
objConn.open strConn
'if new, add employee info
if Request.Form (&quot;txtEmployee&quot;) = &quot;0&quot; then
strSQL = &quot;INSERT EmpInfo(FName,LName,PhoneExt,Email,Fax,CellPhone,Pager,OtherContact,Department,SupervisorFlag,SupervisorID) &quot;
strSQL = strSQL & &quot;VALUES('&quot; & Request.Form(&quot;FName&quot;) & &quot;','&quot; & Request.Form(&quot;LName&quot;) & &quot;','&quot; & Request.Form(&quot;PhoneExt&quot;) & &quot;', &quot;
strSQL = strSQL & &quot;'&quot; & Request.Form(&quot;Email&quot;) & &quot;','&quot; & Request.Form(&quot;Fax&quot;) & &quot;','&quot; & Request.Form(&quot;CellPhone&quot;) & &quot;', &quot;
strSQL = strSQL & &quot;'&quot; & Request.Form(&quot;Pager&quot;) & &quot;','&quot; & Request.Form(&quot;OtherContact&quot;) & &quot;',&quot; & Request.Form(&quot;intDept&quot;) & &quot;,&quot; & Request.Form(&quot;txtHiddenChk&quot;) & &quot;,&quot; & Request.Form(&quot;intSuper&quot;) & &quot;)&quot;
'Open Recordset
set objRec = objConn.execute (strSQL)
Response.Write (&quot;<script>alert('&quot; & Request.Form (&quot;FName&quot;) & &quot; &quot; & Request.Form (&quot;LName&quot;) & &quot; has been added.')</script>&quot;)
else
'if existing, update info
strSQL = &quot;UPDATE EmpInfo &quot;
strSQL = strSQL & &quot;SET &quot;
strSQL = strSQL & &quot;FName='&quot; & Request.Form(&quot;FName&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;LName='&quot; & Request.Form(&quot;LName&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;PhoneExt='&quot; & Request.Form(&quot;PhoneExt&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;Email='&quot; & Request.Form(&quot;Email&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;Fax='&quot; & Request.Form(&quot;Fax&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;CellPhone='&quot; & Request.Form(&quot;CellPhone&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;Pager='&quot; & Request.Form(&quot;Pager&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;OtherContact='&quot; & Request.Form(&quot;OtherContact&quot;) & &quot;',&quot;
strSQL = strSQL & &quot;Department=&quot; & Request.Form(&quot;intDept&quot;) & &quot;, &quot;
strSQL = strSQL & &quot;SupervisorID=&quot; & Request.Form(&quot;intSuper&quot;) & &quot;, &quot;
strSQL = strSQL & &quot;SupervisorFlag=&quot; & Request.Form(&quot;txtHiddenChk&quot;) & &quot; &quot;
strSQL = strSQL & &quot;WHERE ID=&quot; & Request.Form (&quot;txtEmployee&quot;)
'Open Recordset
'Response.Write strSQL
set objRec = objConn.execute (strSQL)
Response.Write (&quot;<script>alert('&quot; & Request.Form (&quot;FName&quot;) & &quot; &quot; & Request.Form (&quot;LName&quot;) & &quot; has been updated.')</script>&quot;)
end if
'clean up
objConn.Close
Set ObjConn = nothing
Set objRec = nothing
end if
end if
%>
<html>
<head>
<meta NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<link REL=&quot;stylesheet&quot; TYPE=&quot;text/css&quot; HREF=&quot;../asm.css&quot;>
<title>Aspen Square Management</title>
<Script language=&quot;Javascript&quot;>
<!--
function checkIt()
{
if (document.f.intSuperFlag.checked == true)
{
//document.f.intSuperFlag.value = &quot;1&quot;;
document.f.txtHiddenChk.value = 1;
}
else
{
//document.f.intSuperFlag.value = &quot;0&quot;;
document.f.txtHiddenChk.value = 0;
}
}
//-->
</Script>
</head>
<body>
<p>
<table border=&quot;0&quot; cellPadding=&quot;1&quot; cellSpacing=&quot;1&quot; width=&quot;100%&quot;>
<tr>
<td width=&quot;200&quot; vAlign=&quot;top&quot;>
<!-- #include FILE=sidebar.inc -->
</td>
<td vAlign=&quot;top&quot; width=*>
<table align=&quot;center&quot; border=&quot;0&quot; cellPadding=&quot;1&quot; cellSpacing=&quot;0&quot; width=&quot;95%&quot;>
<tr height=30>
<td bgColor=&quot;white&quot;><font color=&quot;DarkGreen&quot; face=&quot;Arial&quot; size=&quot;4&quot;><Center><strong> </strong></Center></font></td></tr>
<tr>

<tr>
<td bgColor=&quot;darkgreen&quot;>
<img align=&quot;right&quot; src=&quot;/images/collapse.gif&quot; WIDTH=&quot;12&quot; HEIGHT=&quot;13&quot; onclick=&quot;Hide(News,'imgNews')&quot; name=&quot;imgNews&quot;>
<font color=&quot;white&quot; face=&quot;Arial&quot; size=&quot;2&quot;><strong>Intranet Admin Area
</strong></font></td></tr>
<tr>
<td>
<div id=News>

<font size=2><b>Aspen Employee Info</b><P>

<form name=f method=post>

<UL>

<table border=0 cellspacing=10>
<tr><td colspan=&quot;2&quot;>

           
           
           
<SELECT name=txtEmployee onchange=&quot;window.location='AddEmployee.asp?ID=' + this.value&quot; STYLE=&quot;width: 275px&quot;>
<%
'Open Database
Set objConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Set objRec = Server.CreateObject (&quot;ADODB.Recordset&quot;)
objConn.open strConn
'Create Query String
strSQL = &quot;SELECT ID,FName,LName,Email,PhoneExt,Fax,CellPhone,Pager,OtherContact,Department,SupervisorFlag,SupervisorID FROM EmpInfo &quot;
strSQL = strSQL & &quot;ORDER BY FName&quot;
'Open Recordset
set objRec = objConn.execute (strSQL)
strBuff = &quot;<OPTION value=0>New Employee</OPTION>&quot;
do while not objRec.EOF
if cint(Request.QueryString(&quot;ID&quot;)) = objRec(&quot;ID&quot;) then
strBuff = strBuff & &quot;<OPTION value=&quot; & objRec(&quot;ID&quot;) & &quot; selected>&quot; & objRec(&quot;FName&quot;) & &quot; &quot; & objRec(&quot;LName&quot;) & &quot;</OPTION>&quot;
txtFName = objRec(&quot;FName&quot;)
txtLName = objRec(&quot;LName&quot;)
txtEmail = objRec(&quot;Email&quot;)
txtPhoneExt = objRec(&quot;PhoneExt&quot;)
txtFax = objRec(&quot;Fax&quot;)
txtCellPhone = objRec(&quot;CellPhone&quot;)
txtPager = objRec(&quot;Pager&quot;)
txtOtherContact = objRec(&quot;OtherContact&quot;)
intDepartment = objRec(&quot;Department&quot;)
intSupervisorFlag = objRec(&quot;SupervisorFlag&quot;)
intSupervisorID = objRec(&quot;SupervisorID&quot;)
txtID = objRec(&quot;ID&quot;)
else
strBuff = strBuff & &quot;<OPTION value=&quot; & objRec(&quot;ID&quot;) & &quot;>&quot; & objRec(&quot;FName&quot;) & &quot; &quot; & objRec(&quot;LName&quot;) & &quot;</OPTION>&quot;
end if
objRec.MoveNext
loop
Response.Write strBuff
'clean up
objRec.Close
objConn.Close
Set ObjRec = nothing
Set ObjConn = nothing
%>
</SELECT>
     
<!----------------------------------------------->
<%
if intSupervisorFlag = 1 then
%>
<INPUT type=&quot;checkbox&quot; id=&quot;intSuperFlag&quot; name=&quot;intSuperFlag&quot; onclick=&quot;checkIt();&quot; checked>
<INPUT type=&quot;hidden&quot; name=&quot;txtHiddenChk&quot; value=&quot;1&quot;>
<% else%>
<INPUT type=&quot;checkbox&quot; id=&quot;intSuperFlag&quot; name=&quot;intSuperFlag&quot; onclick=&quot;checkIt();&quot;>
<INPUT type=&quot;hidden&quot; name=&quot;txtHiddenChk&quot; value=&quot;0&quot;>
<%
end if
%>
<!----------------------------------------------->
<Span STYLE=&quot;font-size: 7pt; font-weight: 500; color: red;&quot;>Supervisor - Yes/No</Span>

</td></tr>
<tr><td>

<INPUT type=&quot;text&quot; name=FName size=30 value=&quot;<%=txtFName%>&quot; onchange=&quot;Email.value=FName.value+'_'+LName.value+'@AspenSquare.com'&quot; STYLE=&quot;width: 275px&quot;><BR>
<font size=1 color=black>First Name</font><P>

</td><td>

<INPUT type=&quot;text&quot; name=LName size=30 value=&quot;<%=txtLName%>&quot; onchange=&quot;Email.value=FName.value+'_'+LName.value+'@AspenSquare.com'&quot; STYLE=&quot;width: 275px&quot;><BR>
<font size=1 color=black>Last Name</font><P>

</td></tr>
<tr><td>

<%if Request.QueryString = &quot;0&quot; then%>
<INPUT type=&quot;text&quot; name=Email value=&quot;@AspenSquare.com&quot; size=40 STYLE=&quot;width: 275px&quot;><BR>
<%else%>
<INPUT type=&quot;text&quot; name=Email value=&quot;<%=txtEmail%>&quot; size=40 STYLE=&quot;width: 275px&quot;><BR>
<%end if%>

<font size=1 color=black>Internet Email Address</font><P>

</td><td>

<INPUT type=&quot;text&quot; value=&quot;<%=txtPhoneExt%>&quot; name=PhoneExt STYLE=&quot;width: 275px&quot;><BR>
<font size=1 color=black>Phone Extension</font><P>

</td></tr>
<tr><td>

<INPUT type=&quot;text&quot; name=Fax size=30 value=&quot;<%=txtFax%>&quot; onchange=&quot;FormatPhone(this)&quot; STYLE=&quot;Width: 275px&quot;><BR>
<font size=1 color=black>EFax/Personal Fax Number</font><P>

</td><td>

<INPUT type=&quot;text&quot; name=CellPhone size=30 value=&quot;<%=txtCellPhone%>&quot; onchange=&quot;FormatPhone(this)&quot; STYLE=&quot;width: 275px&quot;><BR>
<font size=1 color=black>Cell Phone Number</font><P>

</td></tr>
<tr><td>

<INPUT type=&quot;text&quot; name=Pager size=30 value=&quot;<%=txtPager%>&quot; onchange=&quot;FormatPhone(this)&quot; STYLE=&quot;width: 275px&quot;><BR>
<font size=1 color=black>Pager Number</font><P>

</td><td>

<INPUT type=&quot;text&quot; name=OtherContact value=&quot;<%=txtOtherContact%>&quot; size=30 STYLE=&quot;width: 275px&quot;><BR>
<font size=1 color=black>Other Contact Info (Main Property, Home Office, etc)</font><P>

</td></tr>
<tr valign=top><td>

<SELECT name=intDept STYLE=&quot;width: 275px&quot;>
<OPTION value=0>---------------------->Select One<----------------------</OPTION>

<%
'Open Database
Set objConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Set objRec = Server.CreateObject (&quot;ADODB.Recordset&quot;)
objConn.open strConn
'Create Query String
strSQL = &quot;SELECT ID, DeptName FROM DeptInfo &quot;
strSQL = strSQL & &quot;ORDER BY DeptName&quot;
'Open Recordset
set objRec = objConn.execute (strSQL)
do while not objRec.EOF
if objRec(&quot;ID&quot;) = intDepartment then
strDept = strDept & &quot;<OPTION value=&quot;&quot;&quot; & objRec(&quot;ID&quot;) & &quot;&quot;&quot; selected>&quot; & objRec(&quot;DeptName&quot;) & &quot;</OPTION>&quot; & vbCrLf
else
strDept = strDept & &quot;<OPTION value=&quot;&quot;&quot; & objRec(&quot;ID&quot;) & &quot;&quot;&quot;>&quot; & objRec(&quot;DeptName&quot;) & &quot;</OPTION>&quot; & vbCrLf
end if
objRec.MoveNext
loop
Response.Write strDept
'clean up
objRec.Close
objConn.Close
Set ObjRec = nothing
Set ObjConn = nothing
%>
</SELECT><BR>
<font size=1 color=black>Department</font>
<br>
<INPUT type=&quot;hidden&quot; name=txtID size=30 value=&quot;<%=txtID%>&quot;><BR>
<INPUT type=&quot;hidden&quot; name=testbox size=30 value=&quot; &quot;>

</td><td>

<SELECT name=intSuper STYLE=&quot;width: 275px&quot;>
<OPTION value=0>---------------------->Select One<----------------------</OPTION>

<%
'Open Database
Set objConn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Set objRec = Server.CreateObject (&quot;ADODB.Recordset&quot;)
objConn.open strConn
'Create Query String
strSQL = &quot;SELECT ID, FName, LName, SupervisorFlag FROM EmpInfo &quot;
strSQL = strSQL & &quot;ORDER BY FName&quot;
'Open Recordset
set objRec = objConn.execute (strSQL)
do while not objRec.EOF
if objRec(&quot;ID&quot;) = intSupervisorID then
strEmp = strEmp & &quot;<OPTION value=&quot;&quot;&quot; & objRec(&quot;ID&quot;) & &quot;&quot;&quot; selected>&quot; & objRec(&quot;FName&quot;) & &quot; &quot; & objRec(&quot;LName&quot;) & &quot;</OPTION>&quot; & vbCrLf
elseif objRec(&quot;SupervisorFlag&quot;) = 1 then
strEmp = strEmp & &quot;<OPTION value=&quot;&quot;&quot; & objRec(&quot;ID&quot;) & &quot;&quot;&quot;>&quot; & objRec(&quot;FName&quot;) & &quot; &quot; & objRec(&quot;LName&quot;) & &quot;</OPTION>&quot; & vbCrLf
end if
objRec.MoveNext
loop
Response.Write strEmp
'clean up
objRec.Close
objConn.Close
Set ObjRec = nothing
Set ObjConn = nothing
%>
</SELECT><BR>
<font size=1 color=black>Supervisor</font>
<br>

</td></tr>
<tr><td align=&quot;center&quot;>

<INPUT type=&quot;submit&quot; name=btnSubmit value=&quot;Add/Update Employee&quot;>

</td><td align=&quot;center&quot;>

<INPUT type=&quot;button&quot; onClick=deleteIt() name=btnDelete value=&quot;  Delete Employee Info &quot;>

</td></tr>
</table>


</form>

</div>
</td>
</tr>
</table>
</td>
</tr>
</table></p>
<!-- #include FILE=footer.inc -->
<%session_info%>
<script>
function FormatPhone(PhoneNumber) {
strInput = PhoneNumber.value.toUpperCase()
strTemp= ''
for (i=0;i<=strInput.length-1;i++) {
strCurrentChar = strInput.charAt(i)
strCurrentCharCode = strInput.charCodeAt(i)
if ((48 <= strCurrentCharCode) && (strCurrentCharCode <= 57)) {strTemp = strTemp + strCurrentChar}
if ((65 <= strCurrentCharCode) && (strCurrentCharCode <= 90)) {strTemp = strTemp + strCurrentChar}
}
strInput = strTemp
strTemp = ''
if ((strInput.length == 11) && (strInput.charAt(0) == &quot;1&quot;)) {strInput = strInput.substr(1)}
if (strInput.length != 10) {
alert ('This phone number should be a valid 10 digit US phone number!')
return
}
strTemp = '('
strTemp = strTemp + strInput.substr(0,3)
strTemp = strTemp + ') '
strTemp = strTemp + strInput.substr(3,3)
strTemp = strTemp + '-'
strTemp = strTemp + strInput.substr(6)
PhoneNumber.value = strTemp
}
</script>
<Script Language=&quot;JavaScript&quot;>
<!--
function deleteIt()
{
var x = <%=Cint(txtID)%>

if(x == &quot;&quot;)
{
document.f.txtEmployee.focus();
}
else
{
value = confirm(&quot;Click 'OK' to delete or click 'Cancel' to abort.&quot;);

if(value == true)
{
document.f.testbox.value = &quot;OK&quot;;
document.f.submit();
}
else
{
document.f.testbox.value = &quot;CANCEL&quot;;
document.f.txtEmployee.focus();
}
}
}
//-->
</Script>
</body>
</html>
 
Wow! Thanks - hopefully, I can figure this out. Even if I don't, I'm sure I'll learn something just by trying.

Thanks again,

M
 
Wasn't my post but I would have posted it sooner or later. Taking the time to post that much code, certainly deserves a star. Thanks for taking your time to help those of us just starting out!!!!! Rob
Just my $.02.
 
Certainly didn't intend to take away from Onpnt. He's a go getter too. Answers most all of my post!!!!! Thanks!!!!!! Rob
Just my $.02.
 
Thanks, I hope it helps. If you need help sifting through the code let me know.
 
rtshort, nothing taken from me and thanks for the compliment.

very appreciated!

nicly done mithrilhall [thumbsup2] [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top