1

Im embedding html codes in java , I have to pass a string value from html to javascript function, I have tried something like this

out.print("<script>init("+macId+")</script>");

but it didn't pass any value if I pass some integer value then it will be fine, then tried this which I have seen in some example

out.print("<script>init(\'"+macId+"\')</script>");

but the result is same ..can anybody help me to solve this, is this method is the right one I need to follow?

2
  • why dont you assign the variable to some input value and get the value of that element in your function with jquery or js. Commented Sep 16, 2015 at 11:42
  • like if some hidden div? then using jQuery "div id.innerHtml "? Commented Sep 16, 2015 at 11:46

1 Answer 1

1

You don't need to escape ' in string:

out.print("<script>init('" + macId + "')</script>");
Sign up to request clarification or add additional context in comments.

Comments

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.