Hi, I'm a new Activ E-book user and just getting into Activ Script, but I'm struggling with what seems like the simplest of scripting tasks!
I have a mixture of non-protected and protected pages in my e-book and have created a very simple script that uses the SET statement to set a string variable called pwdbutton', the intention being to display an 'Enter Password' button on my Contents page if the password for the book has not yet been entered.
The script is as follows:
SET('pwdbutton','<div class={doublequote}floatright{doublequote}><a href={doublequote}##ENTERPASSWORD(){doublequote} title={doublequote}click to enter your password for this ebook{doublequote}><img src={doublequote}enterPassword.gif{doublequote} alt={doublequote}click to enter your password for this ebook{doublequote} /></a></div>')
I am executing the script through the 'On Start' Event Handler.
The Preprocessor is set ON for ALL HTML files.
In my HTML I refer to my variable using the [={pwdbutton}] notation.
When I compile and view the page all I see is [={pwdbutton}], not the value that I set the variable to in the script.
I am a seasoned programmer of some 20 years but this is frustrating the hell out of me!
This doesn't look like a variable to me. It looks more like a "script" function.
If I'm not mistaken, setting a variable should look like....
myURL = "http://thisismywebsite.com"
and you probably need to set it up in the Activ Variable list to be able to call it using.
[={myURL}]
I probably will be corrected, but, if you want to call a function from all of your page you might need to place it in an external js. file and call it from the head of each documents. something like this...
<SCRIPT LANGUAGE="JavaScript" SRC="myscript.js">
This setup will allow each document to call the routine as required.
Here is some better "inline" code to call up the "enter password" routine'
<div> <a href= "#stop" onClick="window.external.ActivRun('##ENTERPASSWORD()'); return false"> Click here to enter your password </a></div>
On a previous post you seemed to have reservations about using JavaScript because some people might have it disabled. These days JavaScript/VBScript is the "norm" for Internet navigation and ecommerce. Without JavaScript most modern sites would not function. Anyone who operates their browser with JavaScript disabled has a very boring Internet experience.
For example in the code to open the "ENTERPASSWORD()" routine. You could use JavaScript, not only to call the function, but also "NOT" call the function if a password was already entered.
BTW: One way to "Set" an Activ Variable "inline" probably would look something like this...
Hi Ron, thanks for you reply and I understand your comments re. JavaScript, etc.
I think I must be missing a big point here... the Active E-book help text states:
-- The following example would set the value of a variable called foo to 4, a variable called bar to hello, and a variable called myvariable to hello world:
With the above example I was simply trying to use the SET statement to assign a string (albeit in this case a block of HTML code) to a variable. I am conditioning this within an IF...ENDIF block that checks the {iscorrectpassword} variable to see if the password has been entered or not, if it has the script would just assign a blank to my variable.
Does this mean that the 'SET' statement doesn't actually work?
I have also tried several of the other string manipulation statements (STRCAT, STRHTML, etc.) but none seem to set a 'Script Variable'.
Hi Ron, thanks for coming back to me and you are correct in how I am trying to use the SET statement.
I had saved the script (posted earlier) in a file called 'startup.as' and set the 'On Start' Event Handler to execute it, the actual entry in the event handler being "#!startup.as".
I also checked that the script was actually executing when launching the e-book by adding a 'NAVIGATE' statement and this checks out, it just seems to ignore my 'SET' statement.
I have even included my script file in an Activ Link within my index.htm page with <A HREF="#!startup.as">Click Here</A>, the result was just the same.
I don't think this is anything to do with the fact that I am trying to SET a variable with a block of HTML code, the code is just the string value that I am trying to assign to the variable. If I modify my startup.as file to contain one very simple SET statement, like
SET('pwdbutton','Test')
I get exactly the same result in my e-book page as previously noted, i.e. [={pwdbutton}]
Here's another example using the SET statement, this one from the ebookcode.com website:
I'm resigning myself to using JavaScript as you previously suggested but I am very dissappointed that even such a simple statement doesn't work, what else I wonder?
Thank you for taking the time to respond. I will take this up with Answers 2000 to see if they can shed any light and will post their response.
I know the SET statements work, I use it all the time, but not in this way.
Here is what I think the problem is.
You are trying to use preprocessor to display the variable you are creating with the SET statement. The problem stems from a misunderstanding of what happens when your eBook is compiled. Preprocessor means exactly that pre-processor. That means it will propagate some existing data into all the HTML pages where you use the preprocessor code. i.e. [={title}]
By its very definition any variable value you are trying to display using preprocessor, must exist before the eBook is compiled.
If you SET a value in an "as" file, that value comes into reality after the eBook is compiled and therefore could never be pre-processed.
To be able to use the value below in preprocessor i.e. [={pwdbutton}]
You would need to add a variable "pwdbutton" in the Activ Variable list i.e. Edit/Activ Variable/Add Variable. and "cut and paste" the text below as a value.
<div class="floatright"><a href="##ENTERPASSWORD()" title=" click to enter your password for this ebook"><img src="enterPassword.gif" alt="click to enter your password for this ebook /></a></div>
Ron's last post, I think pretty much answers the question.
The only thing that I would add, is if you want to display a variable that changes inside your HTML, you can use the DISPLAY statement - but then you have to display the whole page
With any business, it is up to the individual owner of said business to ensure the success of the business. You may make more or less than any sample figures or results that might be quoted on our web sites or other publications. All business involves risk, and many businesses do not succeed. Further, Answers 2000 Limited does NOT represent that any particular individual or business is typical, or that any results or experiences achieved by any particular individual/business is necessarily typical.