0

I use Yii2 Framework and this is my form:

    <?= $form->field($model, 'RIDBibliografia')->textInput(['maxlength' => true, 'style'=>'width:200px', 'format'=>'html'])->label('Numero di sistema edizione') ?>
<button type="button" name="button" id="btnMostra">Clicca per mostrare/nascondere le edizioni</button>

AND this is my js code:

<script type="text/javascript">
    $(function () {
        //Assign Click event to Button.
        $("#btnGet").click(function () {
            var message = "";
            var griglia = $('.edizioni');
            //Loop through all checked CheckBoxes in GridView.
            $("#grid-biblo input[type=checkbox]:checked").each(function () {
                var row = $(this).closest("tr")[0];
                message += row.cells[1].innerHTML;

            });

            //Display selected Row data in Alert Box.
            //alert(message);
            document.getElementById("citazioni-ridbibliografia").value=message;
            $(griglia).hide();
            return false;
        });
    });
</script>

If I click the button, in the input show this value:

<p style="font-style:italic;color:#636363;"> 486</p>

Instead of only 486. How can I remove the html tag? I want to display only the number value. Anyone can help me?? Thank you!!!!

THIS IS THE COLUMN:

['attribute' => 'IDBibliografia',
           
                    'value' => function ($model,$key,$index,$widget) { 
                        
                        if($model->RIDStatoBibliografia === 3) {
                            
                            return "<p style='font-style: italic; color: #636363;'>"." ".$model->IDBibliografia."</p>"; 
                            
                        } else {
                        
                        
                        return $model->IDBibliografia; 
                        
                        }
                    },
               'format' => 'html',
              'width'=>'7%',
              'label' => 'Num. sis. BIB',
              ],
  • Get the text instead of the innerHTML? Please provide enough html to demonstrate the issue as per [mcve] – charlietfl Mar 17 '21 at 11:45
  • 1
    If you don't want HTML, use `.textContent` instead of `.innerHTML`. It's right there in the name, after all :). – Heretic Monkey Mar 17 '21 at 11:49
  • 1
    Does this answer your question? [How to get the pure text without HTML element using JavaScript?](https://stackoverflow.com/questions/6743912/how-to-get-the-pure-text-without-html-element-using-javascript) – Heretic Monkey Mar 17 '21 at 11:50
  • Your suggestion is true, but it prints me also the column label. I want only the raw value. – marcodemurtas Mar 17 '21 at 12:05
  • *it also prints the column label* - what column label? There's no "column label" in your code (nor any obvious checkboxes for that matter). Please provide the *HTML* (not some obfuscated server-side code generator) in a snippet that *demonstrates* the issue. See [mcve]. – freedomn-m Mar 17 '21 at 12:12
  • I edit the question with the column grid where I obtain the value in js. – marcodemurtas Mar 17 '21 at 12:20

0 Answers0