I tried creating a list of buttons for adding symbols to a text area in a form.
loop in blade.php file:
Here $symbols is an array of symbol obejects from the math_symbols table which has the attributes (id,exp,description)
code:
{!! Form::label('Q_desc','description') !!}<br>
{!! Form::textarea('Q_desc','',array('rows'=>'10','cols'=>'70','required'=>'required')) !!}
<ul style="list-style-type:none;">
@foreach($symbols as $symbol)
<li style="display:inline-block;">
{!! Form::button($symbol->exp,array('onclick'=>'addTextAtCaret(Q_desc,$symbol->exp)') !!}
</li>
@endforeach
</ul>
javascript function:
<script type="text/javascript"> function addTextAtCaret(textAreaId,text) { var textArea = document.getElementById(textAreaId); var cursorPosition = textArea.selectionStart; addTextAtCursorPosition(textArea, cursorPosition, text); updateCursorPosition(cursorPosition, text, textArea); } function addTextAtCursorPosition(textArea, cursorPosition, text) { var front = (textArea.value).substring(0, cursorPosition); var back = (textArea.value).substring(cursorPosition, textArea.value.length); textArea.value = front + text + back; } function updateCursorPosition(cursorPosition, text, textArea) { cursorPosition = cursorPosition + text.length; textArea.selectionStart = cursorPosition; textArea.selectionEnd = cursorPosition; textArea.focus();
} </script>
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28YsBEd
via IFTTT
Aucun commentaire:
Enregistrer un commentaire