0

I am using javascript to fetch data from a text box using js.eval() function like :

val amount=js.eval("document.getElementById('amount').value;")

It is working fine when I am writing the id directly i.e. 'amount' in this case. But I want to create a function which will receive the id and then use the variable id. I tried using '$' sign also like :

def getAmount(amount_id:String):Unit={
     println("Amount is : "+js.eval(s"document.getElementById(${id}).value;"))

But it is not working. Any suggestions ?

1 Answer 1

2

Do not use js.eval. Use the interoperability features of Scala.js instead:

import org.scalajs.dom
import dom.html

def getAmount(amount_id:String): Unit = {
  val input = dom.document.getElementById(amount_id).asInstanceOf[html.Input]
  println(s"Amount is : ${input.value}")
}
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent.. Thanks a lot !!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.