# Call JavaScript from AIR

**URL:** <https://forum.kirupa.com/t/call-javascript-from-air/315597>\
**Category:** flash\
**Created:** [October 29, 2010, 9:06pm UTC](https://forum.kirupa.com/t/call-javascript-from-air/315597 "2010-10-29T21:06:26Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stenrap](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@stenrap](https://forum.kirupa.com/u/stenrap)\
**Post date:** [October 29, 2010, 9:06pm UTC](https://forum.kirupa.com/t/call-javascript-from-air/315597/1 "2010-10-29T21:06:26Z")

</div>

Hi all,

I’m having a hell of a time trying to call JavaScript from an AIR application. Here’s what I’m trying to do:

1. Load an HTML page using HTMLLoader.

2. Access a link by its ID in the HTMLLoader object and simulate the JavaScript click() function on that link.

Here’s the JavaScript function in the loaded HTML page (it simply submits a form on the page):

```auto
function submitAssistantForm(direction)
{
    document.theForm.direction.value=direction;
    document.theForm.submit();
    return;
}

```

And here’s the ActionScript code I’m trying:

```auto
var html:HTMLLoader = new HTMLLoader();
html.addEventListener(Event.COMPLETE, splash);
html.load(new URLRequest("...URL omitted..."));

private function splash(e:Event):void
{
    // try to access the element by its ID and call the Javascript click() function on it
    html.window.document.getElementById('HrNext').click(); // this gives error "click is not a function"

    // try to call the Javascript function directly by its name
    html.window.submitAssistantForm('next'); // this gives error "TypeError: Result of expression 'document.theForm' [undefined] is not an object."
}

```

By the way, if I add the HTMLLoader object to the stage and manually click the link with my mouse, everything works perfectly. So I have to believe it’s possible to programmatically send a click event to the link.

I feel like I’m so close. Can anyone point me in the right direction?

Thanks,  
Rob
