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

How to update db & ASP page from buttons 3

Status
Not open for further replies.

scc

Programmer
Apr 30, 2001
218
US
I have a huge form with disabled input boxes for viewing purposes only, except for one area. What I need to do is to allow the user to type a number in a text box, and choose either a + or - button that will call a stored procedure (sprocUpdateVisits) to update the db, and leave the user on this same ASP page but clear the text box. The page needs to be ready for the use to increment/decrement again if needed.

I'm at a loss how to begin.

I have to use VBScript server-side, and JavaScript client-side.

Here's the html tags:


<td align=&quot;right&quot;>
+/- Visits:
</td>
<td>
<input type=&quot;text&quot; name=&quot;AdjustVisits&quot; size=&quot;5&quot;
value=&quot;&quot; >
<input type=&quot;button&quot; name=&quot;btnAdd&quot; value=&quot;+&quot; >
<input type=&quot;button&quot; name=&quot;btnSubtrace&quot; value=&quot;-&quot; >
</td>

Thanks for your help!
 
What you can do is call with the script to a new window, load an asp page in the new window and let this page do the job for updating the database. Then you make the popup window close itself.
 
A similar, but less noticeable, trick is to load the asp page in a hidden iframe by changing the address of the iframe to reflect the target page with your variables passed as a querystring.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
Stoemp or someone else, can you post some sample code for the pop-up window to close itself?

Tarwn, I'm sorry, but your response went right over my head. I'd be interested in knowing more, or seeing some sample code.

Thanks!
 
just use as code inside the window:

self.close()

This will close the window. But you have to be sure the code is only executed when the database is updated, so you'd do best if you place it in the document's body tag:

<body onLoad=&quot;self.close();&quot;>

This will execute if the page is completely loaded, so in most cases this is when the asp code is executed.

I hope I can help you with this.
 
Ok, pretend you need to pull a users top x color preferences out of a table based on someone selecting that user from a drop down box:
Code:
<html>
<head>
<script language=&quot;JavaScript&quot;>
<!--
function dataReceiver(resultStr){
	var arrayResults = resultStr.split(&quot;,&quot;);	// the string is passed as value,value,value,
			//so the last elemt in our new result array will be a null value

	//do whatever you want with the results here
}
//-->
</script>
</head>
<body>
<!-- Normally this would be filled from a db table, but you get the idea -->
How Many Color Preferences? <input type=&quot;text&quot; value=&quot;3&quot; name=&quot;txtNumPref&quot;><br>
Pick a User:<select name=&quot;selUser&quot;>
   <option value=&quot;bob&quot;> bob </option>
   <option value=&quot;joe&quot;> joe </option>
   <option value=&quot;jill&quot;> jill </option>
</select><a href=&quot;#&quot; onClick=&quot;document.getElementById(&quot;ifrm&quot;).src='getPref.asp?user='+selUser.options[selUser.SelectedIndex]+'&numPref='+txtNumPref.value&quot;>Get his they're top preferences!</a>
<iframe id=&quot;ifrm&quot; style=&quot;display:none;&quot;></iframe>
</body>
</html>
The in our asp page called getPref we would make the SQL statement, execute it, then write the results into a javascript function to execute onLoad:
Code:
<%
Option Explicit
Dim sqlStr, objRS
sqlStr = &quot;SELECT TOP &quot; & Request.QueryString(&quot;numPref&quot;) & &quot;* FROM Preferences WHERE user = '&quot; & Request.QueryString(&quot;user&quot;) & &quot;'&quot;

'execute the sql query into our recordset objRS

%>
<html>
<head>
<script language=&quot;JavaScript&quot;>
<!--
function sendBack(){
   parent.dataReceivier(&quot;
   <%
   objRS.MoveFirst
   Do Until objRS.EOF
		Response.Write objRS(&quot;color&quot;) & &quot;,&quot;
		objRS.MoveNext
   Loop
   %>
   &quot;);
}
//-->
</script>
</head>
<body onLoad=&quot;sendBack();&quot;>
</body>
</html>

I have also used this method to write out a table of results in the iframe (change the object.style.display = 'inline'; for it to be seen) and only passed back a result that they choose from the magical appearing results.

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
With enough resources, time, and coffee, anything is possible.
 
I'd make your first page look like:
<iframe name=&quot;hiddenIframe&quot; src=&quot;about:blank&quot; style=&quot;display:none&quot;></iframe>
<form action=&quot;secondPage.asp&quot; target=&quot;hiddenIframe&quot; onsubmit=&quot;this.reset()&quot;>
<table>
<tr>
<td align=&quot;right&quot;>+/- Visits:</td>
<td>
<input type=&quot;text&quot; name=&quot;AdjustVisits&quot; size=&quot;5&quot; value=&quot;&quot;>
<input type=&quot;submit&quot; name=&quot;btnAction&quot; value=&quot;+&quot;>
<input type=&quot;submit&quot; name=&quot;btnAction&quot; value=&quot;-&quot; >
</td>
</tr>
</table>
And make your second page look like this:
<%
If Request(&quot;btnAction&quot;)=&quot;+&quot; Then
objConn.Execute &quot;sprocUpdateVisits '+',&quot; & Request(&quot;AdjustVisits&quot;)
ElseIf Request(&quot;btnAction&quot;)=&quot;-&quot; Then
objConn.Execute &quot;sprocUpdateVisits '-',&quot; & Request(&quot;AdjustVisits&quot;)
End If
%>

This of course assumes your stored procedure is setup to accept 2 parameters, the first being the plus or minus string, the second being the numeric value the user entered.

Adam
 
Sorry... just getting back to this code.

I'm going to try using the hiddenIframe and just have a few questions.

Does the connection code (or include file...) need to go into the secondPage.asp, or does it honor the variables, and connection code in the first page?

Where can I read about iframes?

Thanks
 
OK! I've been working on this all day (&%$^#%%&^!!), and need some help.

The following is sample code. Note when you type in a value on the first page (SamplePage1.asp) it should process the info in SamplePage2.asp, SamplePage2.asp should then close automatically and change the values on the form SamplePage1.

Here's the code for SamplePage1.asp:

<% @ Language =&quot;VBScript&quot; %>
<% Option Explicit %>
<%
Response.Expires = 0
Response.Buffer=True

'Filename: ReferralView.asp
%>

<html>

<body>


<iframe name=hiddenIframe&quot; src=&quot;about:blank&quot;
style=&quot;display:none&quot;>
</iframe>
<table width=&quot;640&quot; align=&quot;center&quot; cellpadding=&quot;1&quot; border=&quot;1&quot;>
<form name='ClaimsView' action=SamplePage2.asp
target=&quot;hiddenIframe&quot;>

<tr>
<td align=&quot;right&quot;>
Visits Approved:
</td>

<td align=&quot;center&quot; width=&quot;100&quot;>
10
<input type=&quot;hidden&quot; name=&quot;Visits&quot; value=&quot;10&quot; >
</td>
<td align=&quot;right&quot;>
Remaining:
</td>
<td align=&quot;center&quot; class=&quot;tdbold&quot;>
<input type=&quot;text&quot; name=&quot;Remaining&quot; value=&quot;3&quot; size=&quot;5&quot; >
</td>
<td align=&quot;right&quot; class=&quot;emphasize&quot;>
+/- Visits:
</td>
<td>
<input type=&quot;text&quot; name=&quot;AdjustVisits&quot; size=&quot;5&quot; value=&quot;&quot; >
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;+&quot; >
<input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;-&quot; >
</td>
</tr>
</form>
</table>

</body>
</html>


and here's the code for SamplePage2.asp

<% @ Language =&quot;VBScript&quot; %>
<% Option Explicit %>
<%

'Filename: AdjustReferralVisits.asp

Dim iReferralNum
Dim iVisits
Dim iAdjustVisits
Dim iAdjustment
Dim iVisitsRemaining

iReferralNum = mid(Request(&quot;ReferralNum&quot;),2)
iVisits = Request(&quot;Visits&quot;)

iAdjustVisits = Request(&quot;AdjustVisits&quot;)



If Request(&quot;Submit&quot;) = &quot;+&quot; then
iAdjustment = iAdjustVisits

ElseIf Request(&quot;Submit&quot;) = &quot;-&quot; then
iAdjustment = - iAdjustVisits
End If

iVisitsRemaining = iVisits + iAdjustment

%>


<html>
<head>
<script language=&quot;javaScript&quot;>
<!--

function sendBack()
{
parent.document.ClaimView.Remaining = (&quot;<%= iVisitsRemaining %> & &quot;);
parent.document.ClaimView.AdjustVisits = &quot;&quot;;
}
//-->
</script>

</head>

<body onLoad=&quot;sendBack();&quot;>

</body>
</html>


 
Also,
parent.document.ClaimView.Remaining = (&quot;<%= iVisitsRemaining %> & &quot;);
parent.document.ClaimView.AdjustVisits = &quot;&quot;;

should be

parent.document.ClaimsView.Remaining.value = (&quot;<%= iVisitsRemaining %> & &quot;);
parent.document.ClaimsView.AdjustVisits.value = &quot;&quot;; Adam
 
I have just one question about the <iframe> tag to process a page. When you do this, does it reload the parent page?

I guess what I'm wondering is if there is a difference in processing when you do this via and <iframe> tag versus a self-referencing page, which I know reloads the page.
 
It shouldn't, basically it loads and process a new page in the iframe then the new page passes data back to your existing page as if the data in the iframe had been there the whole time.
-Tarwn

--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
For my next trick I will pull a hat out of a rabbit (if you think thats bad you should see how the pigeon feels...) :p
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top