Source language: Translate to:

Get variable from browser?

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Get variable from browser?

Postby stu » Thu Oct 08, 2015 6:39 am

Hi,

I been trying to get a variable (?) from a javascript based web application that is used for booking seats. (http://jsc.mm-lamp.com/)
Like clicking on a seat and somehow be able to retrieve the "row_column" (following the example scheme) so I can store that in a database from Neobook. My lack of experience using javascript and Neobook is not helping...

Any idea on how to manage such task?

Regards.
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Get variable from browser?

Postby dpayer » Thu Oct 08, 2015 8:13 am

Stu,

Here is a function I created in NB by adapting a Javascript:

viewtopic.php?t=19229

Take a look at it, especially at the last few lines. When using javascript functions, you define the function and then call it. You submit data via the NB function mechanism using variables defined with this type of name [%1] .

Try doing something and then report where you reach any roadblocks.

David
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Get variable from browser?

Postby stu » Thu Oct 08, 2015 9:07 am

dpayer wrote:Stu,

Here is a function I created in NB by adapting a Javascript:

viewtopic.php?t=19229

Thanks dpayer

Take a look at it, especially at the last few lines. When using javascript functions, you define the function and then call it. You submit data via the NB function mechanism using variables defined with this type of name [%1] .

Try doing something and then report where you reach any roadblocks.

David


Well, what I have done is add window.external.nbSetVar( '[ClickedSeat]', this.settings.label ); to the original code in the example (http://jsc.mm-lamp.com/) and now when I click on a seat it captures the number, so its good, my current problem has mutated into: how can I do something after I click on a seat, so for example if I want to select multiple seats I can stored them comma separated (or whatever) in a variable, that would be the last part of my afternoon project =)

And actually a bit of a background...

Lets say I'm looking into updating a database right?, so I want to book seats 12,13 20 to the same person, I click on them and then then I pass a variable holding 12,13,20 to Neobook so I can carry on working with the data.

Cheers.
User avatar
stu
 
Posts: 320
Joined: Wed Aug 07, 2013 11:37 am

Re: Get variable from browser?

Postby dpayer » Thu Oct 08, 2015 11:10 am

Well, if you poke these values into the database you are using, you should be able to have a subroutine run upon any change in the table (this is set in the place where you use dbpopentable ). This is how you can notify NB that a change has been made and it needs to act upon it.

D
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Get variable from browser?

Postby virger » Thu Oct 08, 2015 10:01 pm

Trate esto, es muy simple, le dejo a su imaginación los cambios necesarios.
Try this, it's very simple, I leave to your imagination the necessary changes.

Code: Select all
NBW Publication Source File
(C)2014 NeoSoft Corp.
Title=Untitled NeoBook Publication
Language=US
NeoBookVer=5.80
ScreenColors=16777216
ScreenWidth=640
ScreenHeight=480
BkndColor=0
ScreenAutoSize=Yes
LinkColor=16711680
WindowStyle=0
WindowOrder=0
WindowPos=0
WindowProps=31
BiDiMode=0
UseUpdateTimer=Yes
ReturnTime=60
ShapeTransColor=536870912
SplashProps=3
CompileType=0
MediaType=0
FilesIncluded=1
FontsIncluded=2
CopyExternalFiles=No
SetupMedia=3
SetupInstDir=C:\MyProgram
SetupTitle=Setup
SetupColors=16711680|0|65535
VersionMajor=1
VersionMinor=0
VersionRelease=0
VersionBuild=0
ReqExLevel=1
CustomFontName=Arial
CustomFontSize=9
CustomFontStyle=0
CustomCharset=1
CacheSize=30
ExtractOp=132
L_OK=OK
L_CANCEL=Cancel
L_YES=Yes
L_NO=No
L_CLOSE=Close
L_ERRORTITLE=Error
L_FINDTITLE=Find
L_FINDPROMPT=Find &What
L_FINDFIRST=&Find First
L_FINDNEXT=Find &Next
L_FINDERROR=Search text not found.
L_PWORDTITLE=Password required
L_PWORDMSG=Before continuing, you must first|enter the correct password.
L_PWORDPROMPT=&Password:
L_PWORDERROR=That's not the right password!
L_MEDIAERROR=In order to play this type of file you must install|the appropriate multimedia hardware and/or|software.
L_INTERNETERROR=Unable to locate Internet Browser software.
L_ABORTFUNCTION=Do you want to cancel this function?
L_EXTRACTERROR=This file could not be extracted and cannot be played.
L_INSTDIRPROMPT=Please enter the drive and directory where you would like this program to be installed. To accept the default drive and directory, simply press Enter.
L_INSTFOLDERPROMPT=Do you wish to create a program folder?
L_INSTRUNPROMPT=Do you want to run
L_INSTDISKPROMPT=Please insert disk #
L_INSTDISKERROR=That's not the correct disk, try again.
L_INSTGENERROR=The installation has terminated.
L_INSTEXITPROMPT=Do you really want to cancel the installation?
L_INSTWINTITLE=Setup
L_INSTPROGTITLE=Extracting Files...
L_SENDEMAIL=Sending Mail...
L_MAILSERVER=Please enter the name of your outgoing email server:
L_COPY=Copy to Clipboard
L_SELECTALL=Select All
L_DONWLOADFILE=Downloading: %s
L_PLEASEWAIT=Please wait...
TrayMenuBegin
MenuName=TrayOpen
MenuText=Open
MenuState=3
MenuKey=0
MenuAction=SetVar "[WindowState]" "Normal"
MenuName=TrayExit
MenuText=Exit
MenuState=3
MenuKey=0
MenuAction=Exit "" ""
MenuEnd
MasterPage
NewPage=New Page
PageStyle=0
PageColor=16777215
PageGradient1=16711680
PageGradient2=255
PageGradientDir=1
WallpaperStyle=0
ObjectType=14
Name=Web
X=-1
Y=2
W=262
H=127
Anchor=0
FileName=[PubDir]sits.html
VarName=[WebStatus]
TitleVarName=[WebTitle]
URLVarName=[WebAddr]
ScrollBar=Yes
LineColor=0
LineWidth=0
LineStyle=0
FillColor=12632256
FillPattern=0
Font=Arial
FontSize=8
FontStyle=0
FontCharset=1
TextColor=0
TabOrder=2
ObjectType=8
Name=Text1
X=18
Y=117
W=213
H=26
Anchor=0
Font=Arial
FontSize=14
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs28\cf0 Data Is [VarNb]}}}
HMargin=0
VMargin=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=14739704
FillPattern=0
TabOrder=3
ObjectType=8
Name=Text2
X=258
Y=2
W=369
H=473
Anchor=0
Font=Arial
FontSize=9
FontStyle=0
FontCharset=1
TextColor=0
Text={\rtf1\ansi\deff0\deftab254{\fonttbl{\f0\fnil\fcharset1 Arial;}}{\pard{\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 <!doctype html>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 <html><head>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 <meta charset="utf-8">\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 <title>SIMPLE EJEMPLO</title>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 <script>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 function EsSitObj(pr)\{\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 \tab var vSit = pr.value;\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 \tab alert(vSit);\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 \tab retorne(vSit);\}\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 function EsSitName(pr)\{\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 var vSit =\tab  document.getElementById(pr).value;\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 alert(vSit);\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 retorne(vSit);\}\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 function retorne(pr)\{\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 window.external.nbSetVar( '[VarNb]', pr );\}\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 </script></head>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 <body>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 <table width="60px" border="1" cellpadding="0">\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0   <tr><th width="9%" scope="col"><input id="Ps11" name="Ps11" type="text" \plain\f0\fs18\cf0 readonly value="A1" size="4"\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0      onclick="EsSitObj(this)"></th>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0     <th width="6%" scope="col"><input name="Ps12" type="text" value="A2" \plain\f0\fs18\cf0 size="4"></th>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0     <th width="85%" scope="col"><input name="Ps13" type="text" value="A3" \plain\f0\fs18\cf0 size="4"></th>  </tr><tr> <th scope="row"> </th>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0     <td> </td>    <td> </td>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0   </tr><tr><th scope="row"> </th>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0     <td> </td>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0     <td><input name="Ps33" readonly type="text" id="Ps33" value="C3" size="4" \plain\f0\fs18\cf0 onclick="EsSitName('Ps33')"></td>  </tr>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs18\cf0 </table></body></html>\par¶\ql\li0\fi0\ri0\sb0\sl\sa0 \plain\f0\fs20\cf0 }}¶}
HMargin=0
VMargin=0
LineColor=0
LineWidth=1
LineStyle=0
FillColor=16645629
FillPattern=0
TabOrder=4


GdoSan/Dr.Sanchez--El Jubilado..Abril 2015
GdoSan/Dr.Sanchez--The Retired..April 2015
COSTA RICA
PURA VIDA
User avatar
virger
 
Posts: 524
Joined: Mon Sep 18, 2006 12:21 pm
Location: Costa Rica, America Central

Re: Get variable from browser?

Postby fkapnist » Fri Oct 09, 2015 1:03 pm

The best way to get a variable from an external web page?

Let's say you want to get a client name from a web page in WebBrowser1 and save it as a NB variable [Name]. You may want to simply copy a browser variable to a NB variable. But that does not always work very well. You must first hard wire the client name in your web page by putting it into a text field, in this case "FirstName," which could be within a form, in this case "Client."

Here is the web page javascript (this action uses the name="Client" not id="Client" javascript tags, etc.)

Code: Select all
<form name="Client"><input type="text" name="FirstName" value="Bob"></form>

or
Code: Select all
<form name="Client"><input type="hidden" name="FirstName" value="Bob"></form>


And here is the NB action. Also note below that a : sign must separate the form name from the field:

Code: Select all
BrowserGetElement "WebBrowser1" "Client:FirstName" "[Name]"


The value for the NB variable [Name] will be "Bob."

So, if you do something like this with the "seats" of your website (instead of the name example), you can add them all to a final list in Neobook, and then assign them to whoever wants to reserve those seats.

You can just keep adding your seat variable, in this case [Seats}, to a local file or listbox with these actions:

FileWrite "" "Append" "[Seats]"
ListBoxAddItem "" "0" "[Seats]"

You might also want to hide or taint out the selected seats from your website to indicate which seats have been taken.



.
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece

Re: Get variable from browser?

Postby dpayer » Tue Oct 13, 2015 7:59 am

fkapnist wrote:The best way to get a variable from an external web page?
Code: Select all
BrowserGetElement "WebBrowser1" "Client:FirstName" "[Name]"

.



So if it is an EXTERNAL (not in NB) web page, how do you determine the name of the browser being searched? Title? ProcessID? AppID?
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1383
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: Get variable from browser?

Postby fkapnist » Tue Oct 13, 2015 9:01 am

dpayer wrote:
fkapnist wrote:The best way to get a variable from an external web page?
Code: Select all
BrowserGetElement "WebBrowser1" "Client:FirstName" "[Name]"

.



So if it is an EXTERNAL (not in NB) web page, how do you determine the name of the browser being searched? Title? ProcessID? AppID?



BrowserGetElement "WebBrowser1" "Client:FirstName" "[Name]"

This is the browser: "WebBrowser1"

it could be any name you give the browser object when you create it (not the current url)

If you mean an external popup IE browser window, you can get its name with the hpwSendKeys plugin.
Assuming it will be the top window once it opens, hpw will find it

If it is from your website you should already know the window title and hpw can perform various actions on it... If it is from your website, instead of opening it in a popup window, it is easier to send the url to WebBrowser2 (for example) where you can have more control to copy, parse or modify the source code with NB actions...

BrowserExport "WebBrowser2" "[sourcecode]"

WebBrowser2 need not be seen by the user (sent to back) and closed when finished...
By "close" I mean empty it
BrowserGoTo "WebBrowser2" "about:blank"
and then make it invisible or disabled

:P

.
User avatar
fkapnist
 
Posts: 348
Joined: Mon Nov 17, 2014 4:24 pm
Location: Greece


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest