Support the ongoing development of Laravel.io →
Views Blade Forms

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>
Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.