jamesmargolis Posted November 6, 2014 Share Posted November 6, 2014 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 https://forums.phpfreaks.com/topic/292313-button-that-adds-a-piece-of-text-into-a-text-area/ Share on other sites More sharing options...
hansford Posted November 6, 2014 Share Posted November 6, 2014 <!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 https://forums.phpfreaks.com/topic/292313-button-that-adds-a-piece-of-text-into-a-text-area/#findComment-1495910 Share on other sites More sharing options...
jamesmargolis Posted November 6, 2014 Author Share Posted November 6, 2014 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 https://forums.phpfreaks.com/topic/292313-button-that-adds-a-piece-of-text-into-a-text-area/#findComment-1495917 Share on other sites More sharing options...
hansford Posted November 7, 2014 Share Posted November 7, 2014 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> Link to comment https://forums.phpfreaks.com/topic/292313-button-that-adds-a-piece-of-text-into-a-text-area/#findComment-1495983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.