Skip to content

Can't get selector example to work #7

@ysangkok

Description

@ysangkok

I am trying to get this example to work:

https://utrechthaskellcompiler.wordpress.com/2010/10/29/a-haskell-ffi-calling-convention-for-javascript/

Here is my source file:

module Hello where

import Language.UHC.JS.Prelude
import Language.UHC.JS.Assorted
import Language.UHC.JS.W3C.HTML5

--data Document
--foreign import js "document"   document      :: IO Document
--foreign import js "%1.write()" documentWrite :: Document -> JSString -> IO ()
--foreign import js alert :: JSString -> IO ()
--
--foreign import js "%1.getElementsByName()" documentGetElementsByName :: Document -> JSString -> IO (NodeList Node)
--
--data NodeList x
--
--foreign import js "%1.length" nodeListLength :: NodeList Node -> Int
--foreign import js "%1[%2]"    nodeListItem   :: NodeList Node -> Int -> IO Node
--
--data Node
--
--foreign import js "%1.innerHTML" elementInnerHTML :: Node -> JSString
--foreign import js "%1.tagName"   elementTagName   :: Node -> JSString

main = do d <- document
          n <- documentGetElementById d (stringToJSString "myHeader")
          alert $ jsStringToString $ elementTagName n
          alert $ jsStringToString $ elementInnerHTML n

I compile using uhc --import-path=uhcjs/uhc-js/src --target=js -O,2 jsffi.hs.

Then, I add an element using echo "<div id='myHeader'>test</div>" >> jsffi.html and then I open jsffi.html. Nothing is alerted.

I tried the example without uhc-js, that did not work either. What could be the problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions