Date:  09/09/2019 04:06:48 PM Msg ID:  004996
From:  Art Bergquist Thread:  004992
Subject:  Re: Call VFP function from JavaScript event
If that doesn't work, I'm back to my original request of being able to run a VFP function from a JavaScript event.
 
After it's run the VFP function, which could write out to a text file on the server or to a VFP table, I could then employ VFP to read the data from the next web page. 
Sent by Art Bergquist on 09/09/2019 11:34:58 AM:
Thanks; the use case was to store information via VFP into a text file for another web page to use; the web page I'm POST-ing to is very similar to the upper section of your Examples\Download.FWx.  As a result, it doesn't have HTML like you have in the lower section of Examples\Download.FWx.
 
Between the time I sent my question below and the time you had responded, I had switched to employing hidden <input>s to store 4 pieces of information the next page uses [I can easily read the hidden <input>s from the next page via Request.Form() calls].
 
I'm now told, though, that HTML5 data- attributes are a better (best?) practice than hidden fields.  I'm currently researching this but am wondering how I would read the values of those data- attributes because I believe I need to employ JavaScript to do that, and to do that, I would need to have HTML.  But, since I'm employing an approach very similar to the upper section of the Examples\Download.FWx, I am only calling Response.Write(...) to write out (e.g., a .PDF file) following by a call to Response.End().
 
Have you any insights WRT how I could read an HTML5 data- attribute set in the previous web page in the above scenario I described?
Sent by FoxWeb Support on 09/03/2019 01:12:02 PM:
The function specified in OnClick events is always javascript. You can call a FoxWeb script from javascript, through AJAX if you want. If yes, I suggest that you use a javascript library that makes it easier to make AJAX calls, such as jQuery.
 
At the same time, I don't understand why you want to call a FoxWeb script through OnClick, instead of simply specifying it in the href attribute. Why not call the script directly? Is it because you are trying to display content from a different page, once the script is done? If yes, you can redirect the user to the other page through the content returned to the browser by the script.
FoxWeb Support Team
support@foxweb.com email
Sent by Art Bergquist on 08/31/2019 05:04:47 PM:
Hi, all.
 
I believe I can do this but am having difficulty getting it to work; I'm building up a string that contains an anchor (<a href ...>).  As part of that string, I'm trying to set up a JavaScript event handler so that when a user clicks on the anchor, it first calls a VFP function (and then goes to the URL specified in href):
 
onclick="<%= RecordDocument() %>"
 
RecordDocument.Prg contains the following code:
 
STRTOFILE('Test message', 'RecordDocument.Txt', .F.)
 
The problem is that when I click on an anchor that has its onclick defined as above, it doesn't appear to run RecordDocument.Prg (since RecordDocument.Txt doesn't get created).
 
I've also tried not including the equals sign, as follows:
 
onclick="<% RecordDocument() %>"

but that didn't work (and I don't believe that's the correct syntax anyway).

Has anyone ever tried doing something like this?

TIA,
 
Art Bergquist