clojurescript: how do i copy one input text field to another?

1,534 views
Skip to first unread message

bob

unread,
Dec 15, 2011, 5:12:58 PM12/15/11
to Clojure

I new to clojurescript and i thought i would take a simple example
like http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick

it has javascript that does the following:

<button
onclick="document.getElementById('field2').value=document.getElementById('field1').value">Copy
Text</button>

i created the following clojurescript

(defn ^:export copytext []
(let [e (dom/getElement "field2")]
(doto e (dom/setTextContent (.value (dom/getElement "field1"))))))

to set the input text field2.

I'm not seeing any errors on the console, but i'm also not seeing the
text being
copied from field1 to field2.

thanks in advance for pointers on how to get this working.

David Nolen

unread,
Dec 16, 2011, 10:29:12 AM12/16/11
to clo...@googlegroups.com
Can you create a paste of your index.html as well as your ClojureScript file?

Thanks!
David


--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

bob

unread,
Dec 16, 2011, 1:05:29 PM12/16/11
to Clojure

here is a link to both: https://gist.github.com/1487157
(hopefully that is what you meant by create a paste. first time
trying it)


On Dec 16, 10:29 am, David Nolen <dnolen.li...@gmail.com> wrote:
> Can you create a paste of your index.html as well as your ClojureScript
> file?
>
> Thanks!
> David
>

> On Thu, Dec 15, 2011 at 5:12 PM, bob <rditm...@gmail.com> wrote:
>
> > I new to clojurescript and i thought i would take a simple example

> > likehttp://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick

drewn

unread,
Dec 18, 2011, 2:22:23 PM12/18/11
to Clojure
I had this problem too. I tried to do it in Pinot+Noir. Haven't
figured it out yet, so curious to see if there's any success with
this!

Gijs S.

unread,
Dec 19, 2011, 5:20:58 AM12/19/11
to Clojure
The problem is the setTextContent function from Google closure. Text
content is the text within a div, span, p, label etc but not the value
of an input element. Likewise getTextContent on field1 returns "",
rather than the value "Hello World!".

The following clojurescript can set the value of a text input field:
(set! (.value (dom/getElement "field2")) (.value (dom/getElement
"field1")))

This is the clojurescript translation for this javascript assignment:

Reply all
Reply to author
Forward
0 new messages