Source language: Translate to:

Trigger a JavaScript onclick event programmatically?

Questions and information about using VBScript and JavaScript in NeoBook functions

Moderator: Neosoft Support

Trigger a JavaScript onclick event programmatically?

Postby domino » Fri Aug 14, 2009 7:51 am

I ought to be able to do this - but can`t so a little help would be most welcome...

I have an HTML form with some javascript to perform conversions.

I would like to create a little pub to "batch process" numbers for conversion.

I can populate and retrieve values programattically....
BrowserSetElement
BrowserGetElement

But I can`t work out how to get NB to "Press the Submit Button" programatically.

ie Trigger an onclick event

Code: Select all
<INPUT id="find" type="button" value="Find" onclick="FindLoc();"><br/>


Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Neosoft Support » Fri Aug 14, 2009 11:08 am

To simulate a button click you need to do something like this:

Code: Select all
BrowserExecScript "WebBrowser1" "document.getElementById([#34]find[#34]).click()" "JavaScript"
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Re: Trigger a JavaScript onclick event programmatically?

Postby dpayer » Fri Aug 14, 2009 11:09 am

domino wrote:I ought to be able to do this - but can`t so a little help would be most welcome...

I have an HTML form with some javascript to perform conversions.

I would like to create a little pub to "batch process" numbers for conversion.

I can populate and retrieve values programattically....
BrowserSetElement
BrowserGetElement

But I can`t work out how to get NB to "Press the Submit Button" programatically.

ie Trigger an onclick event

Code: Select all
<INPUT id="find" type="button" value="Find" onclick="FindLoc();"><br/>


Cheers
Dave


The submit button has an action associated with it. Usually it posts to a webserver somewhere to a file there. You could grab the values in the form of the page via BrowserGetElement process and then send them to the URL with each of the form field values appended to the URL and separated by plus signs.

Example, if the file that the form posts to is form.asp ( or php) then you make the post be:

http://servername.com/form.asp?fieldnam ... yetanother

This way you don't really need to "push the button" you just do what the button was doing.

Try submitting the form with values in a browser and see if you can do a screen capture as it is posting the long URL to the address line of the browser to see if this is close to what you wouldsee. Sometimes in forms the data is encrypted in one way or another.

David P
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Postby domino » Sat Aug 15, 2009 2:59 am

Thanks guys..

Worked like a charm - and yet again a whole new world is revealed.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby domino » Sun Aug 16, 2009 4:27 am

Sorry me again.... :oops:

When attempting to use a BrowserGetElement command I keep getting This Element Does Not Exist errors.

Below are the HTML contents of a Webpage that makes use of the Bing Maps SDK to get the latitude and longitude of the centre of the map.

Clicking Get Info outputs this data into the "output" textbox

So far so good - but if this webpage is opened in NB and I try to use BrowserGetElement to process the contents of the text box - I just get the Element Does Not Exist Error and No Output.

A search through the forum reveals a similar issue with a media player object - but sadly the solution was lost on me.....

If anyone could spare a few moments to paste this into an NB web browser and try a get element - and help me undesrtand what's going on I`d be very grateful.

Cheers
Dave

Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2"></script>

<script type="text/javascript">
var map = null;
              function GetMap()
              {
               map = new VEMap('myMap');
                           map.LoadMap(new VELatLong(52.0, -1.5), 5 ,'h' ,false);         }           
                                 function GetInfo()
                                         
                                          {document.map.output.value = map.GetCenter();}
                                                </script>   </head>   
                                               
                                                <body onload="GetMap();">
                                                <form name="map">
                                               
                                                <div id='myMap' style="position:relative; width:700px; height:350px;"></div>
                                               
                                                                                                              <div>
                                                            <INPUT id="getinfo" type="button" value="Get Info" name="getInfo"  onclick="GetInfo();">
                                                                   <input type="text" name="output" id="T1" value="" size="44"></p>                                                        </div>
                                          </form>
                   
                     </body>
                   </html>
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Neosoft Support » Mon Aug 17, 2009 11:17 am

The problem seems to have something to do with this line:

<body onload="GetMap();">

If I replace that with

<body>

The BrowserGetElement action works correctly.

It may be that Bing has put something in their map rendering code that prohibits access to the page's elements.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby domino » Mon Aug 17, 2009 12:06 pm

Thanks you may have a point about Bing...

I tried without
<body onload="GetMap();">
this and as you say the get element works correctly.

It's also defying any attempts to SendKeys ...

I try a document.write and though it produces a webpage with lat long I can't export the contents of the page ....

I`m afraid JavaScript isn`t my thing but it seems that writing to a file or copying to clipboard isn`t straightforward...

Will persevere though... so any ideas from anyone gratefully received.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Gaev » Mon Aug 17, 2009 4:45 pm

Dave:

This code ...
Code: Select all
BrowserExecScript "WebBrowser1" "GetInfo();window.external.nbSetVar( '[#91]CoOrds[#93]',document.map.output.value);" "JavaScript"
AlertBox "Bing Cords" "[CoOrds]"
... attached to a NeoBook Button works for me.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby domino » Tue Aug 18, 2009 2:04 am

Bingo!

Forever in your debt sir...

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK


Return to NeoBook Functions - VBScript & JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest