Dual action button

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 13 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
johncron
Posts: 4
Last visit: Mon Aug 23, 2010 4:45 am

Dual action button

Post by johncron »

I have searched everywhere for an answer to a problem and hope you guys can help.

On a web page there are links to another web site to download zip files, what I need to be able to do is when the link is activated and the file shown as open/ save etc is to be able to send information to the database via vbscript to say that the user has done this.

I can link and download the zip files or I can send and save the required data to the database, I don't seem to be able to do both with just the one click of a button.

Advice would be much appreciated.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Dual action button

Post by jvierra »

Hello and welcome to ScriptingAnswers.

With System.Net.WebClient you can just use DownloadFile( URL, filename). This takes no clicks but does require the use of PowerShell.

What code are you trying to run?

Sometimes code that we run is executed asynchronously. When this happens events can get lost. Sometimes putting in a sleep command will help but mostly you will find that the focus is getting moved so your action is going to the wrong window.

Your code will be the only way we can get an idea of what you may be doing wrong.

jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Dual action button

Post by jvierra »

Here is a complete example in jscript and vbscript mixed that will do what you are asking.

main asp file demo.html ( can also be an ASP if you need serverside code.

Code: Select all

<html>
<head>
<title>Submit Demo</title>
</head>
<script>
    function submitForm(){
         form1.submit();
    }
</script>
<body>
     <form action="demo2.asp" id="form1" name="ContactUs" method="post">
 <input name="somename" value="somevalue"/>
          <a href="javascript: submitForm()">Search</a>
     </form>
</body>
</html>
</strong>

here is the response file separtaed so you can see it works correctly.

-- demo2.asp

Code: Select all

<script language="vbscript" runat="server">
    Response.Write(Request("somename"))
</script>

The form is a simple HTML form that submits to an ASP response page that just echos back the form variable.

There is nothing trivcky about 'SUBMIT" except that an even has to call in the submit explicitly in code.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Dual action button

Post by jvierra »

I really don't understand what any of this has to do with your original question which was how to link a button to a submit for multiple items in one click. I guess I really don't unferstand what you are trying to dobut it seems like you may be doing way more work than you need to.

A 'Submit' will always return all forms to the server if needed. The submit can be detected on the server by determing that it has come from a 'POST'. YOu can do as many things on teh server as required. Pushing files to the client is one thing but it needs a helper becise security doesn't allow for unmediated pushes in IE and most web browsers. The browser has to coperaate in teh orchestrated push by having the correct bits installed.

The way we usualyy accomplish mutlifile requests is via BITS which is required to be installed on every Windws System since XP SP2 I believe. BITS can be fed wih file names retrieved from the server and download all with logging. The BIT operation is evented for this. This is, of course, how WIndows Update is able to do it's magic. You might use it as a template for how to do this kind of download.


User avatar
johncron
Posts: 4
Last visit: Mon Aug 23, 2010 4:45 am

Dual action button

Post by johncron »

I was orininally thinking 'button' i.e a coloured <td> with text on it, which I have now used with the "vbscript:document.forms(0).submit()" submitter which you suggested. The users I will be dealing with want to see the download window which they can click. To use background intelligent transfer service which would have files mysteriously appear on their machines may frighten then (only joking), BITS is somewhat above my comfort zone.

Perhaps I can send you a screen shot or two so that you can more readily visualise what I am trying to do.

Kind regards
johncron
User avatar
johncron
Posts: 4
Last visit: Mon Aug 23, 2010 4:45 am

Dual action button

Post by johncron »

I'm getting lost.
On my last reply I enclosed the word button in single quotes to signify that it was very broadly referred to as a button as it was something you would click.
Perhaps, like in the Sound of Music, lets start from the very beginning....
I have captured the current user (a regular visitor, one of many) who has accessed this web site via an email flyer sent to them containing a query string which will give me their ID and the ID of the promotional music they would like to listen to. These ID's are used to extract the relevant data for the ;Promotion ;Track reference ;Track URL from the database via a VB dll.
An ASP web page which contains among other elements a vertical column in a table containing up to seven <td>'s 94 px wide and 18 px high, these will contain an anchor and href. Each <td> (block) has the word 'Download' on it and the whole block changes colour and is underlined when it is rolled over.
Immediately to the left on the screen there is an embedded mp3 music player which has up to seven tracks available to listen to, matching those described above, but with the track name written on them.
Here is what I need to do :-
When the user has listened to a track which they like they will click the corresponding (Download) 'button'. From there using the data I have from above, I would like to download a zip file from the Track URL above which they can save to their drive, also I have the user ID and the Track reference which I need to update the database to show they have accessed that track.
Hopefully this makes sense.
Kind regardsjohncron
User avatar
johncron
Posts: 4
Last visit: Mon Aug 23, 2010 4:45 am

Dual action button

Post by johncron »

Thanks for this, however, nowhere above can I continue the single click of whatever it was that was clicked to take me to the database.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Dual action button

Post by jvierra »

Here isa page from a database complete with rollovers and downloadable links. One more line of code and it can have a player too.

http://www.designedsystemsonline.com/demo4.asp

Here is the code:

Code: Select all

<%@ language="VBSCRIPT" %>
<%
    Dim dbpath
    dbpath = Server.MapPath(".music.mdb")
    Dim db,rs
    Set db = CreateObject("ADODB.Connection")
    db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath & ";Persist Security Info=False"
    db.Open
    Set rs = db.Execute("select * from tunes")
%>
<html>
<head>
<meta name="GENERATOR" content="SAPIEN Technologies PrimalScript 2009">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="test.css" />
<title>Document Title</title>
</head>
<body>
<p>Right Click download link and choose 'Save As' to save to a file.</p>
<style>
a:link {color:#0000ff;}
a:visited {color:#ff0000;}
a:hover {background:#66ff66;}
</style>
<table>
    <thead>
        <th><%Response.Write(rs.Fields(0).Name)%></th>
        <th><%Response.Write(rs.Fields(1).Name)%></th>
        <th><%Response.Write(rs.Fields(2).Name)%></th>
        <th>Download Link</th>
    </thead>
<tbody>
<% While Not rs.Eof%>
    <tr>
        <td>
            <% Response.Write(rs.Fields(0).Value) %>
        </td>
        <td>
            <% Response.Write(rs.Fields(1).Value) %>
        </td>
        <td>
            <% Response.Write(rs.Fields(2).Value) %>
        </td>
        <td>
            <a href='<%Response.Write(rs.Fields(2).Value) %>' >download</a>
        </td>
    </tr>
    <%rs.MoveNext%>
<%Wend%>
</tbody>
</table>
</body>
</html>

As you can see there is not much to this code. It just enumerates a database to web page. It can be driven easily from a HTTPQuery by modifying the SQL select statement.
This topic is 13 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked