1

I am using this code to insert text but now i want to add html code in textfield as well.

 <input type="button" class="btn btn-danger btn-flat" value="Bitcoin" onclick="insertText('input-comment', '<iframe src="invoice.php?address=3NUcGsurfneJxMC3vb5hWwgjg5ytTP9daB&amount=10&id=109" width="800px" height="800px" frameborder="0px"></iframe>');">

It is working fine when i put text in it but doesn't work any more when i add this html code. This html code(iframe code) should automatically inserted in textarea on button click.

My js

<script type="text/javascript">
  function insertText(elemID, text)
  {
    var elem = document.getElementById(elemID);
    elem.innerHTML += text;
  }
</script>
4
  • you need to escape the quotes within the function parameters Commented Aug 7, 2016 at 6:50
  • are there any errors in the console? Can you include your js function insertText? Commented Aug 7, 2016 at 7:01
  • added above! <script type="text/javascript"> function insertText(elemID, text) { var elem = document.getElementById(elemID); elem.innerHTML += text; } </script> Commented Aug 7, 2016 at 7:04
  • check the below.... if you use single quotes and escape them in the function parameter it's ok Commented Aug 7, 2016 at 7:05

1 Answer 1

2

Try escaping the double quotes in the function parameters, like:

<input type="button" class="btn btn-danger btn-flat" value="Bitcoin" onclick="insertText( 'input-comment', '<iframe src=\'invoice.php?address=3NUcGsurfneJxMC3vb5hWwgjg5ytTP9daB&amount=10&id=109\' width=\'800px\' height=\'800px\' frameborder=\'0px\'></iframe>' )" /> 

Corrected the previous code - this seems to work

Sign up to request clarification or add additional context in comments.

1 Comment

WORKED! Thank you friend for helping me out

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.