i have a button and a textarea , pressing the button should write [code][/code], everytime the button its clicked

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

i have a button and a textarea , pressing the button should write [code][/code], everytime the button its clicked

dinispt
i have a button and a textarea , pressing the button should write [code][/code], everytime the button its clicked




this is my view form add

<script> function myFunction() { document.getElementById('texto').innerHTML = "Hello JavaScript!"; } </script>

<?php
$title = 'Add new Blog ad';
$this->headTitle($title);
?>

<?php echo $this->escapeHtml($title); ?>


<?php
$form = $this->form;
$form->setAttribute('action', $this->url('bloghome/add', array('action' => 'add')));
$form->prepare();



echo $this->form()->openTag($form) . PHP_EOL;
echo $this->formHidden($form->get('idblogad')) . PHP_EOL;
echo $this->formHidden($form->get('identidade')) . PHP_EOL;
?>
<dl class="zend_form">
<dt><?php echo $this->formLabel($form->get('titulo')); ?></dt>
<dd><?php
    echo $this->formElement($form->get('titulo'));
    echo $this->formElementErrors($form->get('titulo'));
?></dd>

<dd><?php
    echo $this->formElement($form->get('codebutton'));
    echo $this->formElementErrors($form->get('codebutton'));
?></dd>


<dt><?php echo $this->formLabel($form->get('texto')); ?></dt>
<dd><?php
   
    echo $this->formElement($form->get('texto'));
    echo $this->formElementErrors($form->get('texto'));
?></dd>

<dd><?php
    echo $this->formElement($form->get('submit'));
    echo $this->formElementErrors($form->get('submit'));
?></dd>

</dl>
<?php


echo $this->form()->closeTag($form) . PHP_EOL;
?>

___________________________________
the the button in the form file

        $this->add(array(
            'name' => 'codebutton',
            'attributes' => array(
                'type'  => 'button',
                'class' => 'ui-button',
                'value' => '[code][/code]',
                'id' => 'codebutton',
                'onclick'=>"myFunction()",
           
            ),
        ));


___________________________________

whats happening its when i click the button the first time it writes on the textarea
but only the first time , after that when click and click nothing happens


_________
sorry

_______
thanks
Reply | Threaded
Open this post in threaded view
|

Re: i have a button and a textarea , pressing the button should write [code][/code], everytime the button its clicked

dinispt
now its working

<script> function myFunction() { if(document.getElementById('texto').value !== "") { var texto=document.getElementById('texto').value; texto += '[code][/code]'; document.getElementById('texto').value=texto; alert('ola') }else { document.getElementById('texto').value = "[code][/code]"; alert('ole'); } } </script>