I have text area controls on my page, and I had code so that when a user clicks on a text area or presses the 'ENTER' key, this time a list of markers in the text area will be created. But the problem is that if the user clicks on the text area and it creates a bullet list, but if the user does not type anything in the text area, then it should be empty and the bullet should be deleted. In a simple way, the pool of the text area should be deleted if there is no data in it. And one more thing - to prohibit the user to remove the bullet from the text area.
here is my code:
<textarea name="MondayAcomp" id="MondayAcomp" cols="45" rows="5" onKeyDown="if(event.keyCode == 13) return false;" onKeyUp="bulletOnEnter(this.id)" onFocus="onfoc(this.id)" onBlur="onFocOff(this.id)" style="margin: 0px; width: 200px; height: 219px;"></textarea>
Javascript Functions:
function onfoc(id) { if (document.getElementById(id).value == "") { document.getElementById(id).value += '⢠'; } } function onFocOff(id) { if (document.getElementById(id).value == '⢠') { document.getElementById(id).empty; } } function bulletOnEnter(id) { var keycode = (event.keyCode ? event.keyCode : event.which); if (keycode == '13') { event.preventDefault(); document.getElementById(id).value += '\n⢠'; } var txtval = document.getElementById(id).value; if (txtval.substr(txtval.length - 1) == '\n') { document.getElementById(id).value = txtval.substring(0, txtval.length - 1); } }
jsfiddle here
javascript jquery html
Zala krunal
source share