Jump to content

Button that adds a piece of text into a text area


jamesmargolis

Recommended Posts

I’m trying to construct a button that simply writes an "aleph" character into a text area, see below.

My code does not work, can anyone tell me why ? How should I fix it ?

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<title>Example</title>
<script type="text/javascript">
      //JavaScript code goes here
function insertAtEnd(text)
{
  var theArea = document.getElementById("thisArea");
  theArea.value += '' + text + '';;
 
}            
</script>
</head>
<body>
<input type="button" id="aleph" name="aleph" value="Write an aleph"
onClick="javascript:insertAtEnd(\'<span>א</span>\');return(false)" />
<textarea id="thisArea">  </textarea>


</body>
</html>
Link to comment
Share on other sites


<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<title>Example</title>
<script type="text/javascript">
//JavaScript code goes here
function insertAtEnd(text)
{
var theArea = document.getElementById("thisArea");
theArea.value += '' + text + '';

}
</script>
</head>
<body>
<input type="button" id="aleph" name="aleph" value="Write an aleph"
onClick="javascript:insertAtEnd('\'<span>א</span>\'');return(false);" />
<textarea id="thisArea"> </textarea>


</body>
</html>
Link to comment
Share on other sites

 

 

Thanks for your help hansford. Your solution makes the button write something, but the <span> tag is just output "as is" instead of being interpreted as HTML code. The reason I'm putting a <span> around the character is that, if I don't, the text area starts writing right-to-left as in Hebrew after the character has been inserted. And I don't want that behavior since this is meant for texts which short quotes in Hebrew, not texts entirely written in Hebrew.

Link to comment
Share on other sites

Not quite sure what you are trying to do. You can't render html elements in form elements. You can do some crafty CSS tricks to make it appear that way, but can't do it. You can try this as an approach and see if it suits your needs.

<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<head>
<title>Example</title>
<script type="text/javascript">
      //JavaScript code goes here
function insertAtEnd(text)
{
  var theArea = document.getElementById("thisArea");
  theArea.innerHTML = text;

}
</script>
</head>
<body>
<input type="button" id="aleph" name="aleph" value="Write an aleph"
onClick="javascript:insertAtEnd('<span>א</span>');return(false);" />
<div id="thisArea" style="margin-top:20px;width:50px;padding:2px;outline:1px solid #000000;" contenteditable="true"></div>


</body>
</html>
Edited by hansford
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.